Kop*_*ick 2 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);
Run Code Online (Sandbox Code Playgroud)
我找到了解决方案。有一个内置方法
//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();
Run Code Online (Sandbox Code Playgroud)