Has anyone had any luck in converting an HTML page with CSS to PDF on client-side ?
I tried jsPDF by including html2canvas 1.4.1 and jspdf debug 1.5.3 but none of the CSS was applied.
let pdf = new jsPDF('p', 'pt', 'letter')
, source = document.getElementById('content').innerHTML
, specialElementHandlers = {
// element with id of "bypass" - jQuery style selector
'#bypassme': function(element, renderer){
// true = "handled elsewhere, bypass text extraction"
return true
}
}
margins = {
top: 80,
bottom: 60,
left: 40,
width: 522
};
pdf.fromHTML(
source // HTML string or DOM elem ref.
, margins.left // x coord
, margins.top // y coord
, {
'width': margins.width // max width of content on PDF
, 'elementHandlers': specialElementHandlers
},
function (dispose) {
// dispose: object with X, Y of the last line add to the PDF
// this allow the insertion of new lines after html
pdf.save('Test.pdf');
},
margins
)
}
Wondering if server-side is the only way to go.
chrome --no-sandbox --headless --disable-gpu --print-to-pdf https://my-domain.com/page.html
also doesn't render perfectly as it is viewed visually on a desktop sized screen.