KopMaverick
KopMaverick

Reputation: 137

Open the pdf without saving it ,during url to pdf conversion using ironpdf

I am using ironpdf for converting url to pdf. Conversion is successful, but I have to save the document at a location. Is it possible to just display as a memory stream or byte array?

            string authority = HttpContext.Current.Request.Url.Authority;
            string val = "http://"+authority + "/Report/PrintReport.aspx?ID=" + vciInfoReportid;
            string fileName = "url.pdf";
            string fileloc = HttpContext.Current.Server.MapPath("~/"+fileName);
            Renderer.RenderUrlAsPdf(val).SaveAs(fileloc);

Upvotes: 2

Views: 2650

Answers (2)

KopMaverick
KopMaverick

Reputation: 137

I found the solution. There is a inbuilt method for it

            //Conversion of the ASPX file into PDF

            MemoryStream rend=Renderer.RenderUrlAsPdf(val).Stream;

            HttpContext.Current.Response.AddHeader("Content-Type", "application/pdf");

            // let the browser know how to open the PDF document, attachment or inline, and the file name
            HttpContext.Current.Response.AddHeader("Content-Disposition", String.Format("{0}; filename=Print.pdf; size={1}",
              "attachment", rend.Length.ToString()));

            // write the PDF buffer to HTTP response
            HttpContext.Current.Response.BinaryWrite(rend.ToArray());

            // call End() method of HTTP response to stop ASP.NET page processing
            HttpContext.Current.Response.End();

More information can be found in this ASPX to PDF Tutorial

Upvotes: 5

Suseendran Kandasamy
Suseendran Kandasamy

Reputation: 899

Try Google Docs :

Open your pdf in google viewer without download.

http://docs.google.com/viewer?url=http://"+authority + "/Report/PrintReport.aspx?ID=" + vciInfoReportid

Upvotes: 0

Related Questions