Print

Create a PDF

Create a PDF

  • Published by
    Yannick Berges
  • Last modified
    26 April 2021
  • Voting
    Average rating
    3 votes
  • Favourites
  • Concerns
    Component Template
  • Since Version
    3.X
  • Up to date
    Yes
  • Profile concerned
    Webdesigner, Developer

Thanks to charlynancy  for this tuto

Downlaod TCPDF Library and install it
Duplicate a template for editing file
Edit item.php and load modular code

Use this code after

<?php
<!-- EOF item title -->
 endif;
?>

this

<?php
//allow to load a flexicontent field
$myfield_html = FlexicontentFields::getFieldDisplay($item, 'field_resume');
 

// 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, PDF_MARGIN_TOP, 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', '', 10);
 
// add a page
$pdf->AddPage();
 
// create some HTML content
$html = '<h1>HTML Example</h1>
<div>your content</div>
<div style="text-align:center">blabla

more content
//here display a flexicontent field_resume
</div>' . $item->fields['field_resume']->display;

 
// 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'] . 'SOUS_REPERTOIRE/images/' . $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/' . $this->item->alias . '.pdf"><strong>PDF</strong></a>';
?>
© 2018 Flexicontent. All Rights Reserved.
Save
Cookies user preferences
We use cookies to ensure you to get the best experience on our website. If you decline the use of cookies, this website may not function as expected.
Accept all
Decline all
Essential
These cookies are needed to make the website work correctly. You can not disable them.
Display
Accept
Analytics
Tools used to analyze the data to measure the effectiveness of a website and to understand how it works.
Google Analytics
Accept
Decline