Reputation: 1776
I've read here that every html website can be saved as PDF.
This is exactly what a i need. I need to create a "Download to PDF" button that saves the current website to PDF.
Watching the code in that website understand that to save the website as pdf i need to construct every element in the website using javascript?
Can't i simply point to "/ticket.html" as save it as a 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"
));
Upvotes: 3
Views: 1938
Reputation: 2319
You can't save a 'website' to pdf, but it is possible to create a pdf from a 'webpage'.
You can just print a webpage as a pdf or if you want a pdf-button on your site, you can use a 3rd party library. There are server-side libraries and client-side libraries (javascript) for that. Here is an example of such a client-side library: http://mrrio.github.io/jsPDF/
Upvotes: 3