HTML5 download website pdf

I read here that every html site can be saved as PDF.

This is exactly what I need. I need to create a Download to PDF button that saves the current website as PDF.

Observing the code on this website understand that in order to save the website as pdf, I need to build every element of the website with javascript?

Can't I just tell "/ticket.html" how to save it as PDF?

function createPDFLink(fileName) {
    var doc = new pdf();
    // whatever content you want to download
    var a = document.createElement("a");
    a.download = fileName;
    a.title = "download as PDF";
    a.href = doc.output('datauri',{"fileName":name});
    return a;
}

// some paragraph in the page
document.querySelector(
    "p.saveaspdf"
).appendChild(createPDFLink(
    "document-" + document.title + ".pdf"
));

      

+3


source to share


1 answer


You cannot save a "website" in pdf format, but you can create a pdf file from a "webpage".



You can just print the webpage as pdf or if you want to use a pdf button on your site you can use a third party library. There are server-side libraries and client-side libraries (javascript) for this. Here is an example of such a client library: http://mrrio.github.io/jsPDF/

+2


source







All Articles