如何使用CSS和C#中的图像将网页转换为PDF [英] How to convert Webpage into PDF with CSS and images in C#

查看:75
本文介绍了如何使用CSS和C#中的图像将网页转换为PDF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将网页转换成Pdf格式化

我的代码如下所示

工作正常但不能适用Css

所以pdf生成但不作为网页



Response.ContentType =application / pdf;

Response.AddHeader(content-disposition, attachment; filename = TestPage.pdf);

Response.Cache.SetCacheability(HttpCacheability.NoCache);

StringWriter sw = new StringWriter();

HtmlTextWriter hw = new HtmlTextWriter(sw);

this.Page.RenderControl(hw);



StringReader sr = new StringReader (sw.ToString());



文件pdfDoc =新文件(PageSize.A4,10f,10f,100f,0f);

HTMLWorker htmlparser = new HTMLWorker(pdfDoc);

PdfWriter.GetInstance(pdfDoc,Response.OutputStream);

pdfDoc.Open();

htmlparser.Parse(sr);

pdfD oc.Close();

Response.Write(pdfDoc);

Response.End();



请帮助我

感谢先进的

I want to convert Webpage into Pdf formate
My Code as give below
That work fine but can not aply Css
So pdf generate but not as webpage

Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=TestPage.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
this.Page.RenderControl(hw);

StringReader sr = new StringReader(sw.ToString());

Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 100f, 0f);
HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
PdfWriter.GetInstance(pdfDoc, Response.OutputStream);
pdfDoc.Open();
htmlparser.Parse(sr);
pdfDoc.Close();
Response.Write(pdfDoc);
Response.End();

Please help me
thanks in advanced

推荐答案

http://www.aspsnippets.com/Articles/Export-ASP.Net-GridView-to-PDF- with-Custom-Columns-Widths-using-iTextSharp.aspx [ ^ ]


这篇关于如何使用CSS和C#中的图像将网页转换为PDF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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