html2pdf.js icon indicating copy to clipboard operation
html2pdf.js copied to clipboard

Background color is not interpreted correctly

Open jgrDev opened this issue 7 years ago • 9 comments

Hi, the background color is not interpreted correctly. For example, when the background color is white (#FFFFFF), it is interpreted as #FDFDFD. I would like to know how to get a completely white background. Does anyone know what can happen?

html2pdf().from(innerHtml).set({
	            margin: 1,
	            filename: fileName+'.pdf',
	            image: { type: "jpeg", quality: 1},
	            jsPDF: {orientation: 'portrait', unit: 'in', format: 'letter', compressPDF: false},
	            pagebreak: {mode: ['avoid-all']}
            }).save().then(function () {
            	console.log("finish!");
            });

Thanks! web.pdf

jgrDev avatar Nov 22 '18 13:11 jgrDev

So the html element is:

<div style="background-color: #FFFFFF" >
Content of this pdf 
</div>

PDF: #FDFDFD

cablegunmaster avatar Nov 23 '18 08:11 cablegunmaster

So the html element is:

<div style="background-color: #FFFFFF" >
Content of this pdf 
</div>

PDF: #FDFDFD

Right!

jgrDev avatar Nov 23 '18 09:11 jgrDev

Hi @jgrDev, that's interesting! Can you show me how you're setting the styles? If it truly is <div style="..."> then I'm surprised it's not working, but there are other possible causes if you're using a stylesheet.

eKoopmans avatar Jan 27 '19 03:01 eKoopmans

Hi @eKoopmans! The styles are apply through style sheets:

index.html:
<div class="box">...<div>

app.css:
.box{
  background-color: #FFFFFF;
}

I have tried with styles in line, but the result is the same. Thanks!!

jgrDev avatar Jan 28 '19 09:01 jgrDev

any progress? got same issue.It seems will happen to last node. for me, the background turns to #fdfdfd Dashboard Report(20190905) (6).pdf

casyalex avatar Sep 05 '19 02:09 casyalex

I had exactly the same problem, I solved it by decreasing the scale in the options.

Bagu3tte avatar Nov 14 '19 15:11 Bagu3tte

I'm seeing the same issue with colors not loading. For example, I have

  • items rendering down the page all with the same styling from a stylesheet, but it seems to run out of steam and the
  • elements just lose all their styling. Is there a solution for this?
  • charlesmbrady avatar Jan 05 '21 22:01 charlesmbrady

    The solution from @Bagu3tte saved my day 90% of the css applied correctly after turning down scale to 1

    billchau avatar Jun 03 '21 13:06 billchau

    I'm seeing the same issue with colors not loading. For example, I have

    • items rendering down the page all with the same styling from a stylesheet, but it seems to run out of steam and the
    • elements just lose all their styling. Is there a solution for this?

    I'm seeing the same thing! I have a card with a background color that doesn't render at the bottom of the PDF but does render at the top!

    evilsideburns avatar Jun 22 '22 17:06 evilsideburns