asp.net2.0导出pdf文件完美解决方案


Posted on July 25, 2008


关键是itextsharp.dll和ICSharpCode.SharpZipLib.dll两个文件

关键性代码: 

Document document = new Document();
PdfWriter.GetInstance(document, new FileStream(Server.MapPath("example.pdf"), FileMode.Create));
document.Open();
BaseFont bfChinese = 
    BaseFont.CreateFont("C:\\WINDOWS\\Fonts\\simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
Font fontChinese = new Font(bfChinese, 12, Font.NORMAL, new Color(0, 0, 0));
document.Add(new Paragraph(this.TextBox1.Text.ToString(), fontChinese));
iTextSharp.text.Image jpeg = iTextSharp.text.Image.GetInstance(Server.MapPath("1.jpg"));
document.Add(jpeg);
PdfPTable table = new PdfPTable(datatable.Columns.Count);
for (int i = 0; i < datatable.Rows.Count; i++)
{
    for (int j = 0; j < datatable.Columns.Count; j++)
    {
        table.AddCell(new Phrase(datatable.Rows[i][j].ToString(), fontChinese));
    }
}
document.Add(table);
document.Close();

标签:N/A

 

在线学习答案查询入口
微信扫码联系
微信扫码联系