Jquery print page in not adding css

  jquery, laravel, printing

I’m trying to print with jquery, the thing is that the css is not getting applied into the pdf file.

This is my code, i’m using Laravel 7 by the way.

Jquery inside blade.php

 $(document).ready(function(){
        
        $('button[name="print"]').click(function () {
          var stylesheet = '{{ asset("assets/css/print.css") }}';
          console.log(stylesheet);

          var pageTitle = 'CierresReporte',
                      win = window.open('', 'Print', 'width=500,height=300');
                  win.document.write('<html><head><title>' + pageTitle + '</title>' +
                      '<link rel="stylesheet" type="text/css" href="' + stylesheet + '">' +
                      '</head><body>' + $('.table')[0].outerHTML + '</body></html>');
                  win.document.close();
                  win.print();
                  win.close();
                  return false;
        });
      });

Css file:

@media print {

    th, td {
        font-family: Verdana, Arial, Helvetica, sans-serif;
        font-size: 18px;
        color: #000000;
    }
    tr {
        border: 1px solid gray;
    }
    td {
        width: 200px;
        padding: 3px;
    }
    th {
        background-color: #D2E0E8;
        color: #003366
    }
    table {
        border: 1pt solid gray;
        text-align: center;
    }
    }

I’m even printing the path in the console.log and the path is right. I don’t know what could it be.

Thanks!

Source: Laravel

Leave a Reply