简体   繁体   中英

How to convert .aspx page to pdf?

I need to create a pdf from .aspx page. In .aspx page user will enter so many values in textbox and gridview. It also has some tabs with different sections. I did used iTextSharp for creating simple pdf. But here i need to get the values from the page and need to read the tab controls. So is it posible to use iTextSharp or is there any opensource dll available for converting .aspx to pdf..

Give me some idea?

Thanks..

By using ITextsharp library,this can be done by using HTMLWorker :

First Create String builder;

 private StringBuilder sb;

Then add pdf heading from textbox value as:

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

Then add subject to pdf from textbox value as:

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 />");

Then add paragraphs from textbox value as:

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

for table creation take values in 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>");

And so on.You can create pdf from textbox values of aspx page.

Itext Sharp非常简单。关于选项卡,我不知道它可能会工作,因为它适用于分页,我的意思是它将所有内容转换为分页,在单个pdf中单击此处示例

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM