Save PDF file as a byte array or stream using Rotativa
Asked Answered
O

1

4

I'm trying to convert an HTML to a PDF using Rotativa but I want to save it as a byte array or a stream so I can easily attach it to a mail or something. I found a solution here but the file can't be opened by any PDF reader because it's not a supported format or the file is corrupted.

Here is another solution from the same thread but I can't figure out what is the required parameters to pass to this function and I couldn't find any documentation for Rotativa online.

Outshine answered 24/8, 2015 at 12:5 Comment(0)
O
21

I found the solution here

            var actionPDF = new Rotativa.ActionAsPdf("YOUR_ACTION_Method", new { id = ID, lang = strLang } //some route values)
            {
                //FileName = "TestView.pdf",
                PageSize = Size.A4,
                PageOrientation = Rotativa.Options.Orientation.Landscape,
                PageMargins = { Left = 1, Right = 1 }
            };
            byte[] applicationPDFData = actionPDF.BuildPdf(ControllerContext);
Outshine answered 24/8, 2015 at 13:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.