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??

Trombone0904
  • 4,132
  • 8
  • 51
  • 104

0 Answers0