0

im trying to create a pdf file and im trying to return this file on imsonia or webbrowser, but i dont how to do this.

here is my code:

string beneficiarioRelatorio = "Test"

var stream = new MemoryStream();
PdfWriter writer = new PdfWriter(stream);
PdfDocument pdf = new PdfDocument(writer);
Document document = new Document(pdf);
//Paragraph header = new Paragraph(beneficiarioRelatorio);

document.Add(new Paragraph(beneficiarioRelatorio));
document.Close();

//return stream.ToArray();
//System.IO.File.WriteAllBytes("hello.pdf", stream.ToArray());
var teste = new FileStream(stream, FileMode.Open); 
return new FileStreamResult(teste,"application/pdf");
Timothy G.
  • 6,335
  • 7
  • 30
  • 46

1 Answers1

0

try it

        [HttpGet(Name = "GetPDF")]
    public ActionResult  GetPDF()
    {
        string beneficiarioRelatorio = "Test";

        MemoryStream ms = new MemoryStream();
        Document doc = new Document();
        PdfWriter writer = PdfWriter.GetInstance(doc, ms);
        doc.Open();
        doc.Add(new Paragraph(beneficiarioRelatorio));
        doc.Close();
        byte[] bytes = ms.ToArray();

        return File(bytes, "application/pdf");
    }
Majid325
  • 34
  • 5