Sumo15
Sumo15

Reputation: 33

can't able to get the select value in JSPDF

I am trying to save my html page as a PDF

domtoimage.toPng(document.getElementById('PrintForm'))
                .then(function (blob) {
                    var pdf = new jsPDF('p', 'pt', [$('#PrintForm').width(), $('#PrintForm').height()]);

pdf.addImage(blob, 'PNG', 0, 0, $('#PrintForm').width(), $('#PrintForm').height()); pdf.save("test.pdf"); that.options.api.optionsChanged(); });</pre>

In this I can't able to get my select tag value am while am saving as pdf i will get the Default in the select tag.Like below enter image description here

Upvotes: 0

Views: 589

Answers (1)

Rob
Rob

Reputation: 1216

Try this...

var obj = $(".yourclassname")[0]

    var srcwidth = obj.scrollWidth;

    var pdf = new jsPDF('p', 'pt', 'a4');
    pdf.html(obj, {
        html2canvas: {
            scale: 600 / srcwidth
            //600 is the width of a4 page. 'a4': [595.28, 841.89] 
        },
        callback: function () {
            window.open(pdf.output('bloburl'));
        }
    });        

Where yourclassname is your object in the page (or #yourobjectid). srcwidth is the width calculation so your html fits the width of the page. You might need to add some padding to the html to fit inside the pdf (I added 20px to my div). You should be using this version 1.5.3 of jsPdf for the above to work. Hope this helps (works perferctly for me). You should also be using the latest version of html2canvas 1.0.0-rc.5

Upvotes: 0

Related Questions