读书人

使用iTextSharp将页面转为PDF用过的

发布时间: 2012-12-15 15:16:03 作者: rapoo

使用iTextSharp将页面转为PDF,用过的帮下忙

Document document = new Document();
string n = "PDF" + Utility.Utility.GetRandomCode();
PdfWriter.GetInstance(document, new FileStream(Server.MapPath("/uploads/pdfFile/" + n + ".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));

string strHtml = "<html><table style=font: 8.5pt width=4766 border=1 style=border-collapse:collapse;>";
strHtml = strHtml + "<tr align=center class=td1 style=color:White;background-color:#1C5E55;><td></td> <td colspan=9>Nomination Business</td><td colspan=9>Free-Hand Business</td><td colspan=9>Third-Party Business</td><td colspan=9>Co-loading Business</td><td colspan=9>Others Business</td><td colspan=9>Total</td></tr>";
strHtml = strHtml + "</table></html>";

//Paragraph paragraph = new Paragraph(strHtml);
document.Add(new Paragraph(strHtml, fontChinese));
document.Close();

上面是我生成的代码

结果HTML代码就直接输出了,而不是作为标签

怎么转换呢?
[最优解释]
Document document = new Document(); string n = "PDF" + Utility.Utility.GetRandomCode(); PdfWriter.GetInstance(document, new FileStream(Server.MapPath("/uploads/pdfFile/" + n + ".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)); string strHtml = "<html><table style=font: 8.5pt width=4766 border=1 style=border-collapse:collapse;>"; strHtml = strHtml + "<tr align=center class=td1 style=color:White;background-color:#1C5E55;><td></td> <td colspan=9>Nomination Business</td><td colspan=9>Free-Hand Business</td><td colspan=9>Third-Party Business</td><td colspan=9>Co-loading Business</td><td colspan=9>Others Business</td><td colspan=9>Total</td></tr>"; strHtml = strHtml + "</table></html>"; //Paragraph paragraph = new Paragraph(strHtml); document.Add(new Paragraph(strHtml, fontChinese)); document.Close();




[其他解释]
dingdingidngidngidnigsd

读书人网 >asp.net

热点推荐