0

I would like to create a pdf file from HTML content. For this I found the following script: https://github.com/PHP-Einfach/pdf-rechnung

For testing I create a simple file:

$.post("ajax/createPDF.php", {
    content: $('#html2PDF').html()
}, function(response){
        
    console.log(response)
        
})
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="card-body" id="html2PDF"> 
          <div>
                <img src="assets/logo.png" style="width: 28%; margin-right: 50px;">
          </div>
      </div>

My jQuery script get the HTML content of #html2PDF and send it via ajax post to an pdf file, which do the task:

<?

    require_once('tcpdf/tcpdf.php');
    
    
    $html = $_POST['content'];
    
    $pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
    $pdf->SetCreator(PDF_CREATOR);
    $pdf->SetAuthor("IT Service Neuss");
    $pdf->SetTitle('Rechnung Test');
    $pdf->SetSubject('Rechnung Test');
    $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
    $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
    $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
    $pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
    $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
    $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
    $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
    $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
    $pdf->SetFont('dejavusans', '', 10);
    $pdf->AddPage();
    $pdf->writeHTML($html, true, false, true, false, '');
    ob_end_clean();
    $pdf->Output('pdf/myFile.pdf', 'F');

?>

But here I get the following errors / warnings:

Warning: "continue" targeting switch is equivalent to "break". Did you mean to use "continue 2"? in /volume1/web/inc/tcpdf/tcpdf.php on line 17778

Warning: chr() expects parameter 1 to be int, string given in /volume1/web/inc/tcpdf/include/tcpdf_fonts.php on line 1671
<strong>TCPDF ERROR: </strong>[Image] Unable to get the size of the image: assets/logo.png

Any idea??

Ghost108
  • 3,818
  • 8
  • 44
  • 89
  • Did you try with an absolute url for the logo `img` src ? – Philippe Oct 06 '21 at 07:14
  • yes, same error – Ghost108 Oct 06 '21 at 07:21
  • If you look in the "issues" section of your Github link, someone else has reported a similar issue in June with no response yet: https://github.com/PHP-Einfach/pdf-rechnung/issues/4 – droopsnoot Oct 06 '21 at 07:55
  • this is another error: TCPDF ERROR: Some data has already been output, can't send PDF file – Ghost108 Oct 06 '21 at 09:19
  • okay, angain: My Error is: `TCPDF ERROR: [Image] Unable to get the size of the image: assets/logo.png` and NOT `TCPDF ERROR: Some data has already been output, can't send PDF file` – Ghost108 Oct 06 '21 at 10:05
  • Doe this help https://stackoverflow.com/questions/27060947/tcpdf-error-unable-to-get-the-size-of-the-image? – Greg Oct 06 '21 at 10:31

0 Answers0