I'm trying to convert an aspx page to a PDF using the Winnovative HTML to PDF converter, but before the page is converted, I want some javascript to be run. I know the javascript works as I've tested the standalone aspx page without converting it to a PDF. However, when it is converted, it appears that the javascript hasn't been run. I have read the FAQs on the Winnovative website (http://www.winnovative-software.com/FAQ.aspx) and as a result I've added the following to my code to ensure javascript can be allowed to run:
pdfConverter.ScriptsEnabled = True
pdfConverter.InternetSecurityZone = InternetSecurityZone.LocalMachine
Adding this code still didn't work so I tried commenting out my main javascript and testing a very simple bit of javascript to see if that works. The javascript I tried was simply:
var item = $(".items")[0];
items.style.display = "none";
The element with a class of "items" surrounds everything on the page. When I generated the PDF again, all the contents had disappeared as expected. This means that javascript is running.
I then wondered if maybe the PDF is being generated before my javascript has had a chance to run so that's why the effects can't be seen. I found in the Winnovative website's FAQs that the PDF converter has a ConversionDelay property which can be used to specify an additional period of time in seconds to wait for asynchronous content to be loaded before starting PDF rendering. So I added the following:
pdfConverter.ConversionDelay = 30
Even after this delay, my javascript still does not run. Can anyone please offer any guidance? Thanks.
I found that another product from winnovative "EVO HTML to PDF Converter for .NET" does a good javascript execution, it works also with jquery.
Here is the test page:http://www.evopdf.com/evopdfdemo/default.aspx and I tried the conversion successfully with these jQuery rendered pages:
jQuery Accordion (the tabs are correctly rendered)
jQuery pagination (the pages numbers created by jquery are visible)
In this two examples the winnovative html to pdf conversion fails.
EDIT: It seems that the EVO library has problem on relative scripts include not starting with "/"
If you need to link an external script you have three options:
Add a script reference using the Absolute Path like
<script src="www.myserver.com/myjsfile.js" type="text/javascript"></script>
Insert the script inside the original page using the <script> tag
Use a relative path with "/" like
<script src="/myjsfile.js" type="text/javascript"></script>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With