kreya
kreya

Reputation: 1229

When generating pdf checkbox are not show

I m trying to generate pdf using tcpdf in php. If I open it in browser than everythings are fine.There is no error but If save or download the file than in pdf file only checkbox's values are visible and its just put check mark before first checkbox's value. expected output: All checkboxs are show properly.How to add checkbox(tick mark 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');

?>

Upvotes: 5

Views: 5877

Answers (1)

Aanshi
Aanshi

Reputation: 282

Write different name for all checkboxs.

 <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

Upvotes: 2

Related Questions