简体   繁体   English

将ASPX转换为PDF格式

[英]Convert ASPX to PDF format

I have several ASPX web forms which contain all kinds of text boxes, combo boxes, radio button lists, and a lot of other fancy telerik controls. 我有几个ASPX Web表单,其中包含各种文本框,组合框,单选按钮列表和许多其他花哨的telerik控件。 After a form is filled out it needs to be converted to PDF and then printed. 填写表格后,需要将其转换为PDF然后打印。 I tried wkhtmltopdf but the text boxes in the output were all empty. 我尝试了wkhtmltopdf,但输出中的文本框都是空的。 I have also tried iTextSharp but can't seem to get rid of the InvalidCastException from HTMLWorker.Parse(). 我也尝试过iTextSharp,但似乎无法摆脱HTMLWorker.Parse()的InvalidCastException。 I tried the Essential Objects trial version of EO.PDF which worked perfectly except that it would cost lots of money to purchase and probably isn't worth it. 我尝试了EO.PDF的Essential Objects试用版,除了它需要花费很多钱购买并且可能不值得之外。 I seem to find a lot of examples that are only basic html to pdf converters and won't work with controls. 我似乎找到了许多只是基本的html到pdf转换器的例子,并且不能用于控件。 It also seems like many use GridView or similar for iTextSharp, but I don't know much about gridView or if it would help me here. 似乎很多人使用GridView或类似的iTextSharp,但我不太了解gridView或它是否会帮助我。

I need a ideas to try or possibly a solution to my problems with iTextSharp or wkhtmltopdf. 我需要一个想法尝试或可能解决我的iTextSharp或wkhtmltopdf的问题。 Any help would be appreciated. 任何帮助,将不胜感激。 Thanks in advance! 提前致谢!

The fields are coming out blank because the filled-out information is not part of the HTML structure of the code. 这些字段是空白的,因为填写的信息不是代码的HTML结构的一部分。 The browser shows it, but wkhtmltopdf cannot see it. 浏览器显示它,但wkhtmltopdf无法看到它。

Easy work-around: 简单的解决方法:

  1. On form submission, save the submitted values somewhere. 在表单提交上,将提交的值保存在某处。

  2. Generate a new HTML page using the same code as the form page. 使用与表单页面相同的代码生成新的HTML页面。

  3. Pre-fill the form's HTML with the values you saved in Step 1. Eg specify the value attributes on the form with the submitted data: 使用您在步骤1中保存的值预填表单的HTML。例如,使用提交的数据在表单上指定value属性:

     <input type="text" name="customer_name" value="John Doe"> 

wkhtmltopdf can now render the form with the values hard-coded in the HTML. wkhtmltopdf现在可以使用HTML中的硬编码值来呈现表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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