将GridView导出为PDF后,如何在iTextSharp中更改默认字体大小?

| 我在以下链接中使用iTextSharp方法将GridView导出为PDF文档: http://www.aspsnippets.com/Articles/Export-GridView-To-Word-Excel-PDF-CSV-Formats-in-ASP.Net.aspx 代码是这样的:
protected void btnExportPDF_Click(object sender, EventArgs e)
{
    Response.ContentType = \"application/pdf\";
    Response.AddHeader(\"content-disposition\", \"attachment;filename=GridViewExport.pdf\");
    Response.Cache.SetCacheability(HttpCacheability.NoCache);

    StringWriter sw = new StringWriter();
    HtmlTextWriter hw = new HtmlTextWriter(sw);

    GridView1.AllowPaging = false;
    GridView1.DataBind(); 
    GridView1.RenderControl(hw);

    StringReader sr = new StringReader(sw.ToString());
    Document pdfDoc = new Document(PageSize.A4, 10f,10f,10f,0f);
    HTMLWorker htmlparser = new HTMLWorker(pdfDoc);
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream);

    pdfDoc.Open();
    htmlparser.Parse(sr);
    pdfDoc.Close();

    Response.Write(pdfDoc);
    Response.End();  
}
除PDF中的字体大小外,这非常完美。我猜iTextSharp的默认值为Arial和12pt。 是否有办法在整个PDF中全局更改此默认字体及其大小(至少是其大小)? 谢谢!     
已邀请:
        确实有。 (但是我的最初建议不是... Font.DEFFAULTSIZE是\“ static final \”,所以... Derp)。 错...我认为HTMLWorker的样式表代码不会让您设置总体默认字体大小,以为我还没有做太多工作。我可能是错的。您可以按类或标签进行设置,但这可能需要很多工作……嘿! 我认为您可以为\“ body \”设置样式,这将影响其中的所有内容。除非您正在处理HTML片段,否则应该可以做到这一点:
StyleSheet bodySize = new StyleSheet();
Map<String,String> props = new HashMap<String, String>();
props.put(ElementTags.SIZE, \"8\"); 
bodySize.applyStyle(\"body\", props);

htmlparser.setStyleSheet(bodySize);
我这样做的方法是更改​​源代码(com.itextpdf.text.Font.java),这样
Font.DEFAULTSIZE
的声明就可以了,但是我维护着自己的分支……我很奇怪。     
        
BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
iTextSharp.text.Font font20 = iTextSharp.text.FontFactory.GetFont
(iTextSharp.text.FontFactory.HELVETICA,20);
    
        C#
Hashtable props = new Hashtable();
props.Add(ElementTags.SIZE, \"8\");
    

要回复问题请先登录注册