在ASP.NET中将网页另存为PDF [英] Save Webpage as PDF in ASP.NET

查看:128
本文介绍了在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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆