将GridView导出到PDF后,如何更改iTextSharp中的默认字体大小? [英] How to Change Default Font Size in iTextSharp After Exporting GridView to PDF?

查看:173
本文介绍了将GridView导出到PDF后,如何更改iTextSharp中的默认字体大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在以下链接中使用iTextSharp方法将GridView导出为PDF文档:

I am using the iTextSharp method in the following link to export a GridView to a PDF document:

http://www.aspsnippets.com/Articles/Export-GridView- To-Word-Excel-PDF-CSV-format-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。

This works perfect except the font size in the PDF. I guess the defaults for iTextSharp are Arial and 12pt.

有没有办法在整个PDF中全局更改这个默认字体及其大小(至少大小)?

Is there any way to change this default font and its size (at least its size) globally for the whole PDF?

谢谢!

推荐答案

BaseFont bfTimes = BaseFont.CreateFont(BaseFont.TIMES_ROMAN, BaseFont.CP1252, false);
iTextSharp.text.Font font20 = iTextSharp.text.FontFactory.GetFont
(iTextSharp.text.FontFactory.HELVETICA,20);

这篇关于将GridView导出到PDF后,如何更改iTextSharp中的默认字体大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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