Html to PDF WebKit Rendering Engine Not Executing JavaScript

Hello, everything regarding the Html to PDF process appears to be working great for me except one aspect. The web page I am attempting to print has some JavaScript that I am trying to execute inside a script tag at the bottom of the page.

For example (this isn't the JS I'm needing to run, just an example that does not work as I would expect it to):
<script type="text/javascript">
    $("#d232c734-262e-4930-b5f1-04d9401a267a_0").val("test test test");
</script>

I have EnableJavaScript set to true in the WebKit converter settings as well. I have also attempted to place this line inside the function when the window onload event occurs like so. This does not work either and actually locks up the page where I have to go into Task Manager and end the Syncfusion converter process.
window.onload = function () {
     $("#d232c734-262e-4930-b5f1-04d9401a267a_0").val("test test test");
     window.status = "completed";
};

Basically, I don't understand why my JavaScript code is not executing and updating my html prior to the PDF generation.  Any help is appreciated.

3 Replies

SL Sowmiya Loganathan Syncfusion Team February 20, 2020 01:49 PM UTC

Hi Michael,   
  
Thank you for contacting Syncfusion support.   
  
We have tried to reproduce the reported issue, but it is working properly in our end. We have attached the HTML file, output PDF documents for your reference. If still you are facing the same issue, kindly provide the complete HTML file, code snippet and environment details to replicate the issue in our end. So, that it will be helpful for us to analyze and assist you further on this.   
  
  
Regards, 
Sowmiya Loganathan 



MI Michael February 20, 2020 08:58 PM UTC

Thanks so much for the quick reply Sowmiya. I have made it a little further using the example you provided as a test bed. However, now I am having a new problem.  While I am able to get my JavaScript code executing, I am having issues with reading objects stored within data attributes.  Everything is coming up as undefined.  Is there some other setting I need to configure in order for this to work?

Example:
window.onload = function () {
$('#master').find('div.control').each(function (i, e) {
    var th = $(e);
        var controlDefinition = th.data('controlDefinition');
        if (typeof controlDefinition === "undefined") {
            $("#d232c734-262e-4930-b5f1-04d9401a267a_0").val("undefined");
        } else {
            $("#d232c734-262e-4930-b5f1-04d9401a267a_0").val("defined");
        }
    });

    window.status = "completed";
};

The controlDefinition object might look something like this:
{
     "ControlId": "58083931-17d0-450e-a48a-9ffc8401341e",
     "ControlKey": "testKey",
     "ControlValue": "testValue"
}

I am running version 17.4460.0.39.


SL Sowmiya Loganathan Syncfusion Team February 21, 2020 12:48 PM UTC

Hi Michael,   
   
Thank you for the update.    
   
Our HTML to PDF converter will preserve the PDF document, like how the input HTML file is preserved on web browsers. So, kindly ensure that the scripts are working properly in the web browser and the input HTML is displayed properly on web browsers.    
   
If you are facing any issues generated PDF with HTML to PDF conversion, kindly share with us the complete HTML file, output PDF document, the screenshot of the issues, code snippet and environment details to reproduce the issue in our end. So, that it will be helpful for us to analyze and assist you further with this. 
 
Regards, 
Sowmiya Loganathan 


Loader.
Up arrow icon