html2pdf.js
html2pdf.js copied to clipboard
Get output as PNG
I'm trying to get the outtput as PNG. What I tryed so far:
`
const targetElement = document.body;
const options = {
margin: 0,
filename: 'myfile.png',
image: {
type: 'png',
quality: 0.98
},
html2canvas: {
foreignObjectRendering: true,
width: 1016,
height: 659
},
jsPDF: {
unit: 'in',
format: 'letter',
orientation: 'landscape'
},
};
html2pdf().set(options).from(targetElement).toImg().output().then(binaryData => {
let picture = btoa(binaryData);
let anchor = document.createElement('a');
anchor.href = 'data:image/png;base64,' + picture;
anchor.download = 'printscreen-' + Date.now().toString(16) + '.png';
anchor.click();
}`
Hi,
For me below works.
html2pdf().set(opt).from(element).toImg().outputImg().then(img =>{ console.log(img.src);
});