如何使用iTextsharp将css应用于pdf [英] How to apply css to pdf using iTextsharp

查看:50
本文介绍了如何使用iTextsharp将css应用于pdf的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public void pdf()

{

iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet(); < br $>


styles.LoadTagStyle(divM,border,2pt solid red);



styles.LoadTagStyle(divM,size,60pt);

Response.ContentType =application / pdf;

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

Response.Cache.SetCacheability(HttpCacheability.NoCache);



StringWriter stringWriter = new StringWriter();

HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);



divM.RenderControl(htmlTextWriter);

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

文档doc =新文档(PageSize.A2,7f,7f,7f,0f);



FontFactory.GetFont(Verdana,80,iTextSharp.text.BaseColor.RED);



HTMLWorker htmlparser = new HTMLWorker(doc);

htmlparser.SetStyleSheet(styles);

PdfWriter.GetInstance(doc,Response.OutputStream);

doc.Open();

htmlparser.Parse(sr);

doc.Close();

Response.Write(doc);

Response.End();



}



我试过这样。但是我的代码在应用字体大小时不起作用使用itextsharp边框到pdf。如何修改我的代码请任何人帮助我。

解决方案

这个链接可以帮到你

http: //www.codeproject.com/Articles/686994/Create-Read-Advance-PDF-Report-using-iTextSharp-in

public void pdf()
{
iTextSharp.text.html.simpleparser.StyleSheet styles = new iTextSharp.text.html.simpleparser.StyleSheet();

styles.LoadTagStyle("divM", "border", "2pt solid red");

styles.LoadTagStyle("divM", "size", "60pt");
Response.ContentType = "application/pdf";
Response.AddHeader("content-disposition", "attachment;filename=Invoice.pdf");
Response.Cache.SetCacheability(HttpCacheability.NoCache);

StringWriter stringWriter = new StringWriter();
HtmlTextWriter htmlTextWriter = new HtmlTextWriter(stringWriter);

divM.RenderControl(htmlTextWriter);
StringReader sr = new StringReader(stringWriter.ToString());
Document doc = new Document(PageSize.A2, 7f, 7f, 7f, 0f);

FontFactory.GetFont("Verdana", 80, iTextSharp.text.BaseColor.RED);

HTMLWorker htmlparser = new HTMLWorker(doc);
htmlparser.SetStyleSheet(styles);
PdfWriter.GetInstance(doc, Response.OutputStream);
doc.Open();
htmlparser.Parse(sr);
doc.Close();
Response.Write(doc);
Response.End();

}

I have tried like this.But my code is not working while applying font size and borders to the pdf using itextsharp.How to modifiy my code please any one help me.

解决方案

this link may help you
http://www.codeproject.com/Articles/686994/Create-Read-Advance-PDF-Report-using-iTextSharp-in


这篇关于如何使用iTextsharp将css应用于pdf的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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