在使用ironpdf进行网址转换的过程中打开pdf而不保存它

时间:2018-03-30 07:53:22

标签: c# pdf pdf-generation

我使用ironpdf将url转换为pdf。转换成功,但我必须将文档保存在某个位置。是否可以只显示为内存流或字节数组?

            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);

2 个答案:

答案 0 :(得分:1)

我找到了解决方案。有一个内置的方法

            //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();

可在此ASPX to PDF Tutorial

中找到更多信息

答案 1 :(得分:0)

试用Google文档:

在谷歌浏览器中打开你的pdf而不下载。

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