The code used to print the pdf is as follows:
PdfController :
/**
* @Route("/{id}", name="api_article_pdf", methods={"GET"})
*/
public function gepdf2html($id)
{
// 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->SetAuthor('OPAL TPE');
$pdf->SetTitle('Articles');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
// set default header data
$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE . ' 001', PDF_HEADER_STRING, array(0, 64, 255), array(0, 64, 128));
$pdf->setFooterData(array(0, 64, 0), array(0, 64, 128));
// set header and footer fonts
$pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
$pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));
// set default monospaced font
$pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);
// set margins
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
// set auto page breaks
$pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);
// set image scale factor
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
// ---------------------------------------------------------
// set default font subsetting mode
$pdf->setFontSubsetting(true);
// Set font
// dejavusans is a UTF-8 Unicode font, if you only need to
// print standard ASCII chars, you can use core fonts like
// helvetica or times to reduce file size.
$pdf->SetFont('dejavusans', '', 14, '', true);
// Add a page
// This method has several options, check the source code documentation for more information.
$pdf->AddPage();
// set text shadow effect
$pdf->setTextShadow(array('enabled' => true, 'depth_w' => 0.2, 'depth_h' => 0.2, 'color' => array(196, 196, 196), 'opacity' => 1, 'blend_mode' => 'Normal'));
// $id document
$id_d= substr($id, 0,-7);
$id=$id_d-5;
$id=$id/7;
// Set some content to print
// $em = $this->getDoctrine()->getManager();
$query2= $this->em->createQuery('SELECT
a.libelle as libelle,
a.description as desc,
a.prixVenteHt as prixHt,
a.prixVenteTtc as prixTtc
FROM
App\Entity\Dossier\Article as a
WHERE a.id = :id
');
$query2->setParameter("id", $id);
$data = $query2->getResult();
$html = $this->renderView('test.html.twig',
['data' => $data]);
// Print text using writeHTMLCell()
$pdf->writeHTMLCell(0, 0, '', '', $html, 0, 1, 0, true, '', true);
// ---------------------------------------------------------
// Close and output PDF document
// This method has several options, check the source code documentation for more information.
return $pdf->Output('example_001.pdf', 'I');
and my test.html.twig code :
<html>
<head>
</head>
<body>
<table nobr="true" cellspacing="0" cellpadding="1" border="1">
<thead>
<tr style="background-color:silver;"><th>Libelle</th>
<td>Description</td>
<td>Prix V HT</td>
<td>Prix V TTC</td>
</tr>
</thead>
<tbody>
{% for d in data %}<br>
<tr>
<td>{{ d.libelle }}</td>
<td>{{ d.desc }}</td>
<td>{{ d.prixHt }}</td>
<td>{{ d.prixTtc }}</td>
</tr>
{% endfor %}
</tbody>
</table>
</body>
On the first page, everything works fine, but after the first page break the table header floats to the left side.
I tried to fix thead width to resolve the issue, but that didn't works.
I tried very solution on stack or google with no closer result
Another question please : how could i close my tablee before evreeey page break (2)
Thank you so much :)
I think you should fix the width of table in % and height too, so i does not adjust ifself to whatever it wants. Something like :
Make fixed tables and rows where data can fit and then generate it , test it by filling dummy data Edit : for td tag in tr sum the percents tso it gives you 100%