如何将.aspx页面转换为PDF格式?

时间:2012-10-11 10:37:15

标签: c# asp.net pdf itextsharp

我需要从.aspx页面创建一个pdf。在.aspx页面中,用户将在textbox和gridview中输入这么多值。它还有一些不同部分的选项卡。我确实用iTextSharp来创建简单的pdf。但是在这里我需要从页面获取值并需要阅读选项卡控件。那么使用iTextSharp是否可行,或者是否有任何开源dll可用于将.aspx转换为pdf ..

给我一​​些想法?

谢谢..

2 个答案:

答案 0 :(得分:3)

通过使用ITextsharp库,可以使用HTMLWorker来完成:

首先创建字符串构建器;

 private StringBuilder sb;

然后从文本框值中添加pdf标题:

sb.Append("<p style=\"text-align: center;font-size:" + fontSize + "px;font-weight:" + (bold ? "bold" : "normal") + ";\">" + txtHeading + "</p>");

然后从textbox值添加主题为pdf:

sb.Append("<table><tr valign=\"top\"><td>Subj:</td><td style=\"font-size:" + fontSize + "px;font-weight:bold;text-decoration:underline;\">" + txtSubject.text + "</td></tr></table><br />");

然后将文本框值中的段落添加为:

sb.Append("<p style=\"text-align: left;font-size:" + fontSize + "px;font-weight:" + (bold ? "bold" : "normal") + ";\">" + txtParagraph + "</p><br/>");

表创建时采用string [] array

中的值
sb.Append("<table width=\"100%\" cellspacing=\"0\" cellpadding=\"3\" border=\"0.5\"><thead><tr align=\"center\" valign=\"top\">");
            foreach (string str in StringArray)
            {
                sb.Append("<th><strong>" + str + "</strong></th>");
            }
            sb.Append("</tr></thead>");

依此类推。您可以从aspx页面的文本框值创建pdf。

答案 1 :(得分:0)

Itext Sharp相当容易。关于标签,我不知道它可能会起作用,因为它适用于分页,我的意思是它转换分页中的所有内容,在单个pdf中 Click Here For Example

相关问题