Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Remove black bg from pdf(jspdf)?

I have converting from html to pdf by using html2canvas and jspdf.

I am using a3 format pdf but content width ix 1000px. so after 1000px, pdf shows black background.

canvas{
    background: #fff !important;
    background-color: #fff !important
    margin: 0;
}
#cisForm {
    padding: 10px;
    width: 1000px;
    margin: 0;
    background: #fff !important;
}

cisForm is body

<script type="text/javascript">
    window.onload = function() {
            html2canvas(document.body).then(function(canvas) {
                background:'#fff',
                document.getElementById("cisForm").appendChild(canvas);
                document.body.appendChild(canvas);
                var context = canvas.getContext("2d");
                context.fillStyle="#FFFFFF";

                 l = {
                     orientation: 'p',
                     unit: 'pt',
                     format: 'a3',
                     compress: true,
                     fontSize: 8,
                     lineHeight: 1,
                     autoSize: false,
                     printHeaders: true
                 };

                var doc = new jsPDF(l, "", "");
doc.addImage(canvas.toDataURL("image/jpeg"),"jpeg",0,0)
                window.location=doc.output("datauristring")
            });
        }
    </script>

There is no use for this code. This is converting from html to pdf.

and one more question.

Some limited contents only coming in pdf. Some contents are not coming.

Do we need to set no.of pages anywhere?

How to Remove black background from pdfenter image description here

like image 578
Deen Avatar asked Nov 10 '22 05:11

Deen


1 Answers

Try to set your body background-color to #FFFFFF.

like image 71
Eder Ribeiro Avatar answered Nov 15 '22 08:11

Eder Ribeiro