S McKee
S McKee

Reputation: 21

jsPDF returning blank document

I have an order detail page that I want to turn into a pdf. The details are dynamically created on our backend but I want to use the front end to create the pdf so I am using jsPDF.

Here is my code:

    <script>
    function demoFromHTML() {
    var doc = new jsPDF('p', 'in', 'letter');
    var source = $('#open_orders_detail_display_template').first();
    var specialElementHandlers = {
    '#bypassme': function(element, renderer) {
    return true;
}
};

doc.fromHTML(
$('#open_orders_detail_display_template').get(0),
0.5, // x coord
0.5, // y coord
{
'width': 7.5, // max width of content on PDF
'elementHandlers': specialElementHandlers
});

doc.output('dataurl');
}
</script>

When I run it I don't get any errors but a blank page populates. Any help would be greatly appreciated. Thanks!

Upvotes: 2

Views: 1791

Answers (1)

Rohan Mulay
Rohan Mulay

Reputation: 349

var doc = new jsPDF();
// We'll make our own renderer to skip this editor
    var specialElementHandlers = {
        '#editor' : function(element, renderer) {
            return true;
        }
    };

    // All units are in the set measurement for the document
    // This can be changed to "pt" (points), "mm" (Default), "cm", "in"
    doc.fromHTML($('#render_me').get(0), 30, 50, {
        'width' : 170,
        'elementHandlers' : specialElementHandlers
    });

    doc.save('sample-file.pdf');

Give id="render_me" to div what you want to render. for example

<table id="render_me"></table>

Upvotes: 2

Related Questions