tsayen / dom-to-image

Generates an image from a DOM node using HTML5 canvas
Other
10.32k stars 1.68k forks source link

Hidden content not printed into the pdf #209

Open kruthikaa opened 6 years ago

kruthikaa commented 6 years ago

Hi, I am using domtoimage to take a screenshot of the page and download as pdf. I'm still new at it. So normally when i try capturing a hidden content using html2canvas, i have an option called onclone. But i don't know what to use for domtoimage.

In my page, there is some data that appears in a dialog box. Following is the code i used to capture the data that is hidden in dialog.

html2canvas(main,{onclone:function(document){ var hiddendiv=document.getElementById('maincomment'); hiddendiv.style.display='block'; }}) .then((canvas) => { const imgData = canvas.toDataURL('image/png'); console.log(imgData); pdf.addImage(imgData, 'JPEG', 0, 0); pdf.save("LapSurvey.pdf"); });

But i want the same result in domtoimage. I tried same onclone in domtoimage. It didn't work.

Can anyone help me with this thing!

hjrobinson commented 5 years ago

You can use a style option. See the main page and go to the reference for style. Also see this: https://github.com/tsayen/dom-to-image/issues/21

In short: domtoimage.toBlob(document.getElementById('yourElement'), {style:{'background-color': 'white'}}).then(function (blob) { saveAs(blob, "your.png"); });

AntoscencoVladimir commented 2 years ago

@hjrobinson Thanks for that