Conversion Trigger

By default, the HTML to PDF converter automatically starts the conversion shortly after all the contents of the page (such as images) are fully loaded.

Sometimes you may need to perform some additional initialization tasks with JavaScript and the conversion should not start until your initialization code is done. In this case you can either increase HtmlToPdf.Options.MinLoadWaitTime to give the JavaScript code more time to run, or manually trigger the conversion from JavaScript.

To manually trigger conversion from JavaScript, you must:

  1. Set HtmlToPdf.Options.TriggerMode to Manual or Dual;
  2. Call convert method on eoapi to notify the HTML to PDF converter to start the conversion;

    JavaScript
    //Start the conversion. Note that this is only necessary 
    //when HtmlToPdf.Options.TriggerMode is set Manual or Dual.
    //The default value is Auto, so the conversion starts 
    //automatically.
    //You may also use variable "eoapi" to check whether the page
    //is running inside the converter so that the custom triggering
    //code will not run inside a regular browser because variable
    //"eoapi" does not exist in a regular browser
    if (window.eoapi && eoapi.isEOPdf())
        eoapi.convert();

It is important to understand that:

  • It is only necessary to call eoapi.convert() when you have explicitly set HtmlToPdf.Options.TriggerMode to Manual or Dual. The default value is Auto, which means the conversion starts automatically shortly after the page contents are loaded;
  • Once you set HtmlToPdf.Options.TriggerMode to Manual or Dual, you must call eoapi.convert() in order for the conversion to start, otherwise the conversion will time out and fail;
  • If you set HtmlToPdf.Options.TriggerMode to Dual, the converter will still wait for page contents to be loaded even after eoapi.convert() is called.