How to use Wkhtmltopdf converter with filled text boxes?

你。 提交于 2019-12-08 02:39:43

问题


I need to convert several aspx pages to PDF when a button is clicked. This happens after many text boxes are filled and other controls are selected, etc. Wkhtmltopdf renders the pdf very nicely but everything is blank. Basically, when the PDF is created it is in the state that the form was in on load. I want the PDF to be in the state that the form is in when the button is pressed. I need ideas for a way to work around this issue in order to save the pdf with the text boxes filled.


回答1:


wkhtmltopdf renders an HTML page it "sees", not how the browser displays it. When you fill out the form, the values in the fields are not part of the underlying HTML structure (though they are part of the DOM). As a work-around, you can do the following:

  1. Capture and save all of the form parameters' values somewhere (session, file, database, etc) when the form is submitted.

  2. Generate a new HTML page using the same code as the form page.

  3. Fill in the form values you had saved directly into the HTML code. In other words, specify the value attributes on the form with the inputs you captured.

    For example, if you have a text field called customer_name and the user submitted John Doe, hard-code the value into the tag:

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

Now wkhtmltopdf can render the form with the values filled out.



来源:https://stackoverflow.com/questions/17701409/how-to-use-wkhtmltopdf-converter-with-filled-text-boxes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!