将Html页面转换为PDF文件 [英] Convert Html Page to PDF File

查看:95
本文介绍了将Html页面转换为PDF文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将带有html table tag选项的html页面转换为asp.net中的pdf



    html   text     i  想要  to   convert   to   pdf        















< img src = http:// localhost:56814 / Quotation / images / head.jpgstyle =width:100%/>





 


















< td colspan =3> PK



引用否

00005



nj

报价日期

26/04/2012

PK

查询日期

09 / 09/2010

bhatt

亲切的注意事项

123

AHMEDABAD

333333

电话

787878787

GUJARAT









尊敬的先生/女士




感谢您的询问,我们希望报出以下项目的最低价格。











项目 价格/单位 备注 图像









1.



make

PN061549845

SAFTY





腰带




合规:NA





Rs。

381

/

Nos。

Markand < img id =grdItemList_ctl02_imgItemsrc =http:// localhost:56814 / Quotation / images / default.jpgstyle =height:70px; width:70px; border-width:0px; />














< td> 30天

付款条款

有效期

销售税

交货时间表

运费

7天

增值税15%





支付










如有任何疑问,请随时通过电子邮件或电话与我们联系。

感谢您并期待有机会为您尊敬的组织服务。







< img src =http:// localhost:56814 / Quotation / images / logo.jpg/>







解决方案

需要下载iTextSharp dll。它是一个免费工具。



http:// sourceforge.net/projects/itextsharp/files/latest/download [ ^ ]





  public   void  HTMLToPdf( string  HTML, string  FilePath)
{

凭证凭证= 凭证();

PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + \ Test.pdf,FileMode.Create));
document.Open();

iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
// styles.LoadTagStyle(。barcode,font-size,50px);
// styles.LoadTagStyle(。barcode,font-family, 3 of 9条形码);
// styles.LoadTagStyle(。barcode, color,Green);
hw.Parse( new StringReader(HTML));
document.Close();
ShowPdf( Test.pdf);
}
私有 void ShowPdf( string s)
{
Response.ClearContent();
Response.ClearHeaders();
Response.AddHeader( Content-Disposition inline; filename = + s);
Response.ContentType = application / pdf;
Response.WriteFile(s);
Response.Flush();
Response.Clear();

}


也许您会对此解决方案感兴趣:

http://eleriumsoft.com/PDF_NET/HTML2PDF/Examples/Create_PDF_using_HTML_string.aspx [ ^ ]

但它不是免费的。


http://forums.asp.net/p/1132131/1797686。 aspx [ ^ ]

http://pdfcrowd.com/web-html-to-pdf-net/ [ ^ ]

http://stackoverflow.com/questions/5068954/asp-net-how-to-convert-html-page-to-pdf [ ^ ]


convert html page with html table tag option to pdf in asp.net

The html text which i want to convert to pdf is as follows








<img src="http://localhost:56814/Quotation/images/head.jpg" style="width: 100%" />



 










To
Quote No
00005
The
nj
Quote Date
26/04/2012
PK
Inquiry Date
09/09/2010
bhatt
Kind Attentions
123
AHMEDABAD
333333
Phone
787878787
GUJARAT
PK




Dear Sir/Madam


Thank you for your inquiry, we wish to quote our lowest for the following items.





ItemPrice/UnitRemarksImage





1.

make
PN061549845
SAFTY


Belt


Compliance:NA



Rs.
381
/
Nos.
Markand <img id="grdItemList_ctl02_imgItem" src="http://localhost:56814/Quotation/images/default.jpg" style="height:70px;width:70px;border-width:0px;" />







Payment Terms
Validity
Sales Tax
Delivery Schedule
Freight
7 Days
VAT 15%
30 days

Days
Paid





In case of any futher queries please feel free to contact us by E-mail or Phone.
Thanking you and looking forward to the opportunity to serve your esteemed Organisation.




<img src="http://localhost:56814/Quotation/images/logo.jpg" />



解决方案

NEED TO DOWNLOAD iTextSharp dll. it is a free tool.

http://sourceforge.net/projects/itextsharp/files/latest/download[^]


public void HTMLToPdf(string HTML, string FilePath)
       {

           Document document = new Document();

           PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "\Test.pdf", FileMode.Create));
           document.Open();

           iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();
           iTextSharp.text.html.simpleparser.HTMLWorker hw = new iTextSharp.text.html.simpleparser.HTMLWorker(document);
           //styles.LoadTagStyle(".barcode", "font-size", "50px");
           //styles.LoadTagStyle(".barcode", "font-family", "3 of 9 Barcode");
           //styles.LoadTagStyle(".barcode", "color", "Green");
           hw.Parse(new StringReader(HTML));
           document.Close();
           ShowPdf("Test.pdf");
       }
       private void ShowPdf(string s)
       {
           Response.ClearContent();
           Response.ClearHeaders();
           Response.AddHeader("Content-Disposition", "inline;filename=" + s);
           Response.ContentType = "application/pdf";
           Response.WriteFile(s);
           Response.Flush();
           Response.Clear();

       }


Maybe you will be interested in this solution:
http://eleriumsoft.com/PDF_NET/HTML2PDF/Examples/Create_PDF_using_HTML_string.aspx[^]
But it is not free.


http://forums.asp.net/p/1132131/1797686.aspx[^]
http://pdfcrowd.com/web-html-to-pdf-net/[^]
http://stackoverflow.com/questions/5068954/asp-net-how-to-convert-html-page-to-pdf[^]


这篇关于将Html页面转换为PDF文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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