0

Below is the code for export HTML page to PDF using jquery. All is working properly except I get Black Background colour in the content part of the grid . How to remove this Black colour from the grid content part. I have tried different Js and solutions but either CSS is not applied or if it's applied getting this error.

<script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/0.9.0rc1/jspdf.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2canvas/0.4.1/html2canvas.js"></script>


 $(document).on("click", "#exporttopdf", function () {
            var cache_width = $('.main-sec').width(); //Criado um cache do CSS
            var a4 = [595.28, 841.89]; // Widht e Height de uma folha a4
         //   $(".main-sec").width((a4[0] * 1.33333) - 10).css('max-width', 'none'); 

            // Aqui ele cria a imagem e cria o pdf
            html2canvas($('.main-sec'), {
                onrendered: function (canvas) {

                    //var src = canvas.toDataURL("image/png");
                    var img = canvas.toDataURL("image/jpeg", 1.0);
                  //  var img = canvas.toDataURL("image/png");
                    //var doc = new jsPDF({ unit: 'px', format: 'a4' });//this line error
                    var doc = new jsPDF('landscape'); // default is portrait
                  //  doc.addImage(src, 'PNG', 20, 20);
                   doc.addImage(img, 'JPEG', 20, 20);
                    doc.save('GridData.pdf');
                    //Retorna ao CSS normal
                    $('.main-sec').width(cache_width);
                }
            });
BPDESILVA
  • 2,040
  • 5
  • 15
  • 35
Gargee
  • 11
  • 1
  • 10
  • Possible duplicate of [How to make transparent color white instead of black in canvas?](https://stackoverflow.com/questions/14584946/how-to-make-transparent-color-white-instead-of-black-in-canvas) – Anurag Srivastava Jul 26 '19 at 08:01
  • Thanks for the the help.It worked and saved my time .But still I get some lines drawn in PDF file which is not in my HTML page.How to solve that? – Gargee Jul 26 '19 at 08:39
  • You should ask another question with relevant code for it. – Anurag Srivastava Jul 26 '19 at 09:37
  • I have used same code .Didn't add anything new but it created some lines in same pattern in one column only. – Gargee Jul 29 '19 at 07:32

0 Answers0