Skip to content

Instantly share code, notes, and snippets.

@micker
Created April 26, 2021 19:03
Show Gist options
  • Save micker/502f1170b985694063a40a3050d8c0d8 to your computer and use it in GitHub Desktop.
Save micker/502f1170b985694063a40a3050d8c0d8 to your computer and use it in GitHub Desktop.
PDF generator
<?php
// Include the main TCPDF library (search for installation path).
require_once JPATH_LIBRARIES . '/tcpdf/tcpdf.php';
// create new PDF document
$pdf = new TCPDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
// remove default header
$pdf->setPrintHeader(false);
// set footer fonts
$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, 10, PDF_MARGIN_RIGHT);
$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 font
$pdf->SetFont('dejavusans', '', 8);
// ici je recupere toutes les valeurs contenus
$_position_name_spec = "spec";
if (isset($item->positions[$spec])) {
foreach ($item->positions[$_position_name] as $field){
$specs = '<tr><td>'. $field->label .'</td><td>'. $field->display .'</td></tr>';
}
}
// add a page
$pdf->AddPage();
// début de mon contenu dans le pdf
$html = '
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="50%"><img class="img-responsive" src="https://eurogrip.com/images/logo.png" alt="" width="150px"></td>
<td width="50%"><div style="margin-top:0px;"><h1 style="border-left:2px solid #055DA8;border-bottom:1px solid #055DA8;padding-left:10px;height:20px;">'.$item->title.'</h1></div></td>
</tr>
</table>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<br/>
<br/>
<td width="100%">
<img src="https://eurogrip.com'. $item->fields['gallerie']->thumbs_src['large'][0] . '" />
</td>
</tr>
</table>
<br/>
<br/>
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>
<td width="45%"><div class="description">'. $item->text .'</div></td>
<td width="10%"></td>
<td width="45%">
<br/>
<h2 style="border-left:2px solid #055DA8;border-bottom:1px solid #055DA8;padding-left:10px;height:20px;">SPECS</h2>
' .$specs.' // je veus charger le resultat de ma boucle
</td>
</tr>
</table>';
// output the HTML content
$pdf->writeHTML($html, true, false, true, false, '');
// reset pointer to the last page
$pdf->lastPage();
//Close and output PDF document, save pdf in /images/
$pdf->Output($_SERVER['DOCUMENT_ROOT'] . 'images/pdf-product/' . $this->item->alias . '.pdf', 'F');
//becaurefull adapt the good folder to your config 'SOUS_REPERTOIRE/images/'
//ex 'SOUS_REPERTOIRE/images/'
//complet url /var/www/default/SOUS_REPERTOIRE/images
// Now we will add a link to the pdf
echo '<a target="_BLANK" href="/images/pdf-product/' . $this->item->alias . '.pdf" class="btn btn-success"><strong>PDF product</strong></a>';
?>
<!-- End PDF -->
@micker
Copy link
Author

micker commented Apr 26, 2021

je vais checker je t'ai ouvert les droits je pense
merci

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment