DocRaptor Home
PDF Code Examples

Code Example: Element

<canvas> elements created by JavaScript are not passed to our PDF rendering engine. This is because the graphical data in a <canvas> is not stored in the HTML,. A workaround is to extract the canvas data into raw image data before the PDF rendering.

Here is some example code that will likely require some minor modification to work for your document:

  docraptorJavaScriptFinished = function() {
    var chartCanvas = document.getElementById("canvas");

    // do not do anything unless the chart is finished rendering
    if(chartCanvas == null || < 1)
      return false;

    // dump the canvas to an img tag
    var imageElement = document.createElement("img"); = "width: 100%;";
    imageElement.src = chartCanvas.toDataURL("image/png");
    return true;

Ready to get started? Try DocRaptor for free with unlimited test documents.