asp.net2.0匯出pdf檔案完美解決方案【月兒原創】
阿新 • • 發佈:2019-02-14
{
Document document =new Document();
PdfWriter.getInstance(document, new FileStream(Server.MapPath("Chap0101.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("pic015.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();
}
Document document =new Document();
PdfWriter.getInstance(document, new FileStream(Server.MapPath("Chap0101.pdf"), FileMode.Create));
document.Open();
BaseFont bfChinese = BaseFont.createFont("C://WINDOWS//Fonts//simsun.ttc,1", BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
document.Add(new Paragraph(this.TextBox1.Text.ToString(), fontChinese));
iTextSharp.text.Image jpeg = iTextSharp.text.Image.getInstance(Server.MapPath("pic015.jpg"));
document.Add(jpeg);
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();
}