When creating a pdf checkbox not displayed

I am trying to create a PDF using tcpdf in php. If I open it in a browser, than everything is all right. There is no mistake. If you save or load a file, and not just a PDF file, then only the check boxes are displayed and its check box is in front of the first check box. Expected Result: All flags are displayed correctly. How to add a checkbox (label square) for all values?

Here is my code:

<?php
error_reporting(0);
$file = "PDF.csv"; 
$handle = fopen($file,"r"); 
$data= fgetcsv($handle);  
$job_no=$data[0];
$postcode=$data[1];
$address=$data[2];
$order_no=$data[4];
$d_date=$data[5]; 
$product=$data[8];
$myArray = explode(utf8_encode(''), $product);  
$date = DateTime::createFromFormat("Y-m-d", $d_date);
$filename="General ". $date->format("d"). $date->format("M").$y=$date->format("y").".pdf";
$filepath="C:\\Users\\Admin\\Documents\\pdf";   

require_once('tcpdf_include.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->setFooterData(array(0,64,0), array(0,64,128));
// set some language-dependent strings (optional)
if (@file_exists(dirname(__FILE__).'/lang/eng.php')) {
require_once(dirname(__FILE__).'/lang/eng.php');
$pdf->setLanguageArray($l);
}
// add a page
$pdf->AddPage();
$pdf->SetFont('times', '',11);
$pdf->setPage(1, true);
$txt = '<style type="text/css">
    .height1
    {
    height:1000px;
    }
    </style>
    <table border="1" cellpadding="6" cellspacing="0" width="100%" style="font-family:Arial, Helvetica, sans-serif">

    <tr>
    <td colspan="2">
 <input type="checkbox" name="product[]" value="Electrician"'.(in_array("Electrician",$myArray) ? ' checked="checked" ' : '') .'>Electrician
 <input type="checkbox" name="product[]" value="Painter"'.(in_array("Painter",$myArray) ? ' checked="checked" ' : '') .'>Painter
 <input type="checkbox" name="product[]" value="Specialist company"'.(in_array("Specialist company",$myArray) ? ' checked="checked" ' : '') .'>Specialist company
 </td>      </tr>

</table>';
$pdf->writeHTML($txt,1,null,null,null,null);
// ---------------------------------------------------------
$fileNL = $filepath."\\".$filename;
$pdf->Output($fileNL,'F');

?>
+4
source share
1 answer

Enter a different name for all checkboxes.

 <input type="checkbox" name="product1" value="Electrician"'.(in_array("Electrician",$myArray) ? ' checked="checked" ' : '') .'>Electrician
 <input type="checkbox" name="product2" value="Painter"'.(in_array("Painter",$myArray) ? ' checked="checked" ' : '') .'>Painter
<input type="checkbox" name="product3" value="Specialist company"'.(in_array("Specialist company",$myArray) ? ' checked="checked" ' : '') .'>Specialist company
+1
source

Source: https://habr.com/ru/post/1536547/


All Articles