在ASP.NET中将网页另存为PDF

编程入门 行业动态 更新时间:2024-10-26 02:25:29
本文介绍了在ASP.NET中将网页另存为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如何将网页保存为pdf ... Response.ContentType =application / pdf Response.AddHeader( content-disposition,attachment; filename = psno.pdf) Response.Cache.SetCacheability(HttpCacheability.NoCache) Dim sw As New StringWriter() Dim hw As New HtmlTextWriter(sw) Me.Page.RenderControl(hw) Dim sr As New StringReader(sw.ToString()) Dim pdfDoc作为新文档(iTextSharp.text.PageSize.A4,10.0F,10.0F,10.0F,0.0F) Dim htmlparser作为新HTMLWorker(pdfDoc) PdfWriter.GetInstance(pdfDoc,Response.OutputStream) pdfDoc.Open() htmlparser.Parse(sr) pdfDoc.Close() Response.Write(pdfDoc) Response.End() 这个工作正常...... 如果网页上有任何图片,则不能工作。 它显示 无法找到文件''C:\ ....'' htmlparser.Parse(sr) 错误... 帮我完成这个任务... \\ / 在此先感谢... 有问题, Jaison Joe ......

解决方案

我从不使用iTextSharp。但概念是带有图像的网页不是纯粹的字符串类型。它实际上是二进制类型。因此,您需要使用Response.BinaryWrite对象而不是Response.Write,并且在阅读时您应该读取为字节数组。 以下链接可能会有所帮助,但是实现是使用SautinSoft.PdfVision组件。 如何对保存的网页功能于PDF的甲酸盐的通过-C-夏普

使用HTML页面生成PDF文档ASP.NET [ ^ ]

How to save webpage as pdf... Response.ContentType = "application/pdf" Response.AddHeader("content-disposition", "attachment;filename=psno.pdf") Response.Cache.SetCacheability(HttpCacheability.NoCache) Dim sw As New StringWriter() Dim hw As New HtmlTextWriter(sw) Me.Page.RenderControl(hw) Dim sr As New StringReader(sw.ToString()) Dim pdfDoc As New Document(iTextSharp.text.PageSize.A4, 10.0F, 10.0F, 10.0F, 0.0F) Dim htmlparser As New HTMLWorker(pdfDoc) PdfWriter.GetInstance(pdfDoc, Response.OutputStream) pdfDoc.Open() htmlparser.Parse(sr) pdfDoc.Close() Response.Write(pdfDoc) Response.End() This works properly... If any images are in the webpage it cannot work. It shows Could not find file ''C:\....'' in htmlparser.Parse(sr) error... help me to dom this task...\ Thanks in Advance... With regards, Jaison Joe...

解决方案

I never user iTextSharp. But the concept is the webpage with image is not pure string type. It is actually binary type. So instead of Response.Write you need to go Response.BinaryWrite object and also when reading you should read as byte array. The following link might be helpful,but its implementtion is use SautinSoft.PdfVision component. how-to-save-webpage-in-pdf-formate-through-C-Sharp

Generate PDF documents from a HTML page using ASP.NET[^]

更多推荐

在ASP.NET中将网页另存为PDF

本文发布于:2023-07-27 03:06:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219977.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:另存为   中将   网页   ASP   NET

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!