Syed Abdur Rehman Kazmi
Syed Abdur Rehman Kazmi

Reputation: 1647

VueJS PDF Converter

The issue I am having is I want to convert my Vue HTML in to a pdf and download it for user. I have tried using JSPDF

but it downloads an empty page. It does download when I pass only text to it.

var doc = new jsPDF();

// All units are in the set measurement for the document
// This can be changed to "pt" (points), "mm" (Default), "cm", "in"
setTimeout(function () {
doc.fromHTML(document.getElementById('profile'), 15, 15, {
'width': 170
});

doc.save('two-by-four.pdf')
} , 6000);

How can I solve this ?

Upvotes: 0

Views: 15210

Answers (2)

Makara NGEOM
Makara NGEOM

Reputation: 11

createPDF () {
    let pdfName = 'mes-enfants'; 
    var doc = new jsPDF();

    doc.fromHTML(document.getElementById('print'), 15, 15, {
      'width': 170
    });

    doc.save(pdfName + '.pdf');
}

Upvotes: 1

Boston Kenne
Boston Kenne

Reputation: 818

try to use canvas to convert the content of your html page in base 64 before printing the result. this is my own function, printing using canvas

printFacture() {
    var pdf = new jsPDF();
    var element = document.getElementById('facture');
    var width= element.style.width;
    var height = element.style.height;
    html2canvas(element).then(canvas => {
        var image = canvas.toDataURL('image/png');
        pdf.addImage(image, 'JPEG', 15, 40, width, height);
        pdf.save('facture' + moment(this.facture.date_debut).format('LL') + '_' + moment(this.facture.date_fin).format('LL') + '.pdf';
    });
}

hope it will help you.

Upvotes: 1

Related Questions