Reputation: 4491
I am using tcpdf to create pdf. PDF creation is working but i want to format those data. but i am not getting desired output. i want following format for my PDF(Attached image), but i am not getting. Please help to get output in desired format.
my code is this:
<?php
// Include the main TCPDF library (search for installation path).
require_once('tcpdf_include.php');
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// set document information
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetTitle('Lorem Ipsum');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->AddPage();
$appendBlock = '';
foreach ($res as $key => $value) {
$appendBlock .= '<table><tr>
<td>
<img class="hw" style="width:150px;" src="'.$bar_code.'"> '.$username.'
<b style="float:right;">Date:</b> <br/>
'9-4-2015'
'address of the user'
'887766554433,009988775566'
<b>Description:</b>'.Lorem ipsumLorem ipsumLorem ipsumLorem ipsum.'
<b>ProductCode:</b>'2012' 'red' '9'
'10-4-2015'
</td>
</tr>
</table>
<hr>';
}
//mprd($appendBlock);
// create some HTML content
$html = '
<!DOCTYPE html>
<html>
<head>
'.$style.'
</head>
<body>
<section id="page">
'.$appendBlock.'
</section>
</body>
</html>';
// output the HTML content
//$pdf->writeHTML($html, true, 0, true, 0);
// set default font subsetting mode
//$pdf->setFontSubsetting(true);
// set font
// $pdf->SetAutoPageBreak(TRUE, 0);
$pdf->SetFont('helvetica', '', 11);
// $pdf->writeHTML($html, '', 0, '', false, 0, false, false, 0);
$pdf->writeHTML($html);
// reset pointer to the last page
$pdf->lastPage();
// ---------------------------------------------------------
$name = strtotime('Y-m-d H:i:s');
//Close and output PDF document
$pdf->Output('test.pdf', 'I');
//============================================================+
// END OF FILE
//============================================================+
I am getting this type of format:
Upvotes: 0
Views: 3759
Reputation: 602
First, you should consider changing your PDF Library to mPDF which you can download using this link below.
Link to Library Version 5.7: http://mpdf1.com/repos/MPDF57.zip
Unzip and upload the folder to your site root directory and adjust your path as per your required directory structure.
Based on the code you have provided, consider here is your complete html code that we are going to consider as final output in order to have this for pdf file.
Make all the suitable adjustments as per your requirements as it should best work for your in all cases.
As you are doing the PDF files for THAI Language so you need to define the Language parameter in your initialization.
$mpdf = new mPDF('th');
and for setting default font you can do: $mpdf->SetAutoFont(AUTOFONT_THAIVIET);
For further reference you can read this manual for adding THAI fonts:
http://mpdf1.com/manual/index.php?tid=453
Here is your final code:
<?php
$appendBlock = '<table>
<tr>
<td><img class="hw" style="width:150px;" src="AMC_AA23"> MOHSIN <b style="float:right;">Date:</b> <br/>
9-4-2015
เรดมอนด์พาร์ทเม้นท์, เรดมอนด์พาร์ทเม้นท์,เรดมอนด์พาร์ทเม้นท์
887766554433,009988775566 <b>Description:</b>Lorem ipsumLorem ipsumLorem ipsumLorem ipsum <b>ProductCode:</b>2012 red 9
10-4-2015 </td>
</tr>
</table>
<hr>
<table>
<tr>
<td><img class="hw" style="width:150px;" src="AMC_AA23"> MOHSIN <b style="float:right;">Date:</b> <br/>
9-4-2015
เรดมอนด์พาร์ทเม้นท์, เรดมอนด์พาร์ทเม้นท์,เรดมอนด์พาร์ทเม้นท์
887766554433,009988775566 <b>Description:</b>Lorem ipsumLorem ipsumLorem ipsumLorem ipsum <b>ProductCode:</b>2012 red 9
10-4-2015 </td>
</tr>
</table>
<hr>
<table>
<tr>
<td><img class="hw" style="width:150px;" src="AMC_AA23"> MOHSIN <b style="float:right;">Date:</b> <br/>
9-4-2015
เรดมอนด์พาร์ทเม้นท์, เรดมอนด์พาร์ทเม้นท์,เรดมอนด์พาร์ทเม้นท์
887766554433,009988775566 <b>Description:</b>Lorem ipsumLorem ipsumLorem ipsumLorem ipsum <b>ProductCode:</b>2012 red 9
10-4-2015 </td>
</tr>
</table>
<hr>
<table>
<tr>
<td><img class="hw" style="width:150px;" src="AMC_AA23"> MOHSIN <b style="float:right;">Date:</b> <br/>
9-4-2015
เรดมอนด์พาร์ทเม้นท์, เรดมอนด์พาร์ทเม้นท์,เรดมอนด์พาร์ทเม้นท์</p>
887766554433,009988775566 <b>Description:</b>Lorem ipsumLorem ipsumLorem ipsumLorem ipsum <b>ProductCode:</b>2012 red 9
10-4-2015 </td>
</tr>
</table>
<hr>
<table>
<tr>
<td><img class="hw" style="width:150px;" src="AMC_AA23"> MOHSIN <b style="float:right;">Date:</b> <br/>
9-4-2015
เรดมอนด์พาร์ทเม้นท์, เรดมอนด์พาร์ทเม้นท์,เรดมอนด์พาร์ทเม้นท์
887766554433,009988775566 <b>Description:</b>Lorem ipsumLorem ipsumLorem ipsumLorem ipsum <b>ProductCode:</b>2012 red 9
10-4-2015 </td>
</tr>
</table>
<hr>
<table>
<tr>
<td><img class="hw" style="width:150px;" src="AMC_AA23"> MOHSIN <b style="float:right;">Date:</b> <br/>
9-4-2015
เรดมอนด์พาร์ทเม้นท์, เรดมอนด์พาร์ทเม้นท์,เรดมอนด์พาร์ทเม้นท์
887766554433,009988775566 <b>Description:</b>Lorem ipsumLorem ipsumLorem ipsumLorem ipsum <b>ProductCode:</b>2012 red 9
10-4-2015 </td>
</tr>
</table>
<hr>
<table>
<tr>
<td><img class="hw" style="width:150px;" src="AMC_AA23"> MOHSIN <b style="float:right;">Date:</b> <br/>
9-4-2015
เรดมอนด์พาร์ทเม้นท์, เรดมอนด์พาร์ทเม้นท์,เรดมอนด์พาร์ทเม้นท์
887766554433,009988775566 <b>Description:</b>Lorem ipsumLorem ipsumLorem ipsumLorem ipsum <b>ProductCode:</b>2012 red 9
10-4-2015 </td>
</tr>
</table>
<hr>
<table>
<tr>
<td><img class="hw" style="width:150px;" src="AMC_AA23"> MOHSIN <b style="float:right;">Date:</b> <br/>
9-4-2015
เรดมอนด์พาร์ทเม้นท์, เรดมอนด์พาร์ทเม้นท์,เรดมอนด์พาร์ทเม้นท์,
887766554433,009988775566 <b>Description:</b>Lorem ipsumLorem ipsumLorem ipsumLorem ipsum <b>ProductCode:</b>2012 red 9
10-4-2015 </td>
</tr>
</table>
<hr>
';
require_once('mpdf.php');
$mpdf = new mPDF('th');
$mpdf->SetAutoFont(AUTOFONT_THAIVIET);
$html = '<p lang="th">'.$appendBlock.'</p>';
$html = iconv("UTF-8","UTF-8//IGNORE",$html);
$mpdf->WriteHTML($html);
$mpdf->Output(dirname(__FILE__)."/myfile.pdf", "F");
?>
Upvotes: 1