• English
  • Case Studies
  • Products & Services
    • Business Innovation via Digitalization
    • Mobile and Web Apps
    • Websites and Portals
    • Supporting Services
    • ICT4D Solutions
    • omnivote eVoting Solution
  • Company
    • Social Business
    • People
    • Careers
  • Blog
  • Contact Us
  • Case Studies
  • Products & Services
    • Business Innovation via Digitalization
    • Mobile and Web Apps
    • Websites and Portals
    • Supporting Services
    • ICT4D Solutions
    • omnivote eVoting Solution
  • Company
    • Social Business
    • People
    • Careers
  • Blog
  • Contact Us
  • English
PDF logo

Publish your data from TYPO3 as Website and as PDF with TCPDF

/ Technology

Ever needed to create a PDF document from your data on-the-fly? Web Essentials has created a solution for one of its clients which allows to publish job advertisements

  • online on a website and
  • as PDFs for print

from a single central source: the TYPO3 Content Management System.

The PDF solution is based on theTCPDF library. It allows to generate all sorts of PDFs as can be seen in theexamples section of TCPDF which comes with PDF and according PHP snippet.

But as usual, the difficulty lies in the detail. In the case of our client, we needed to produce PDF documents to a given width, but with a flexible height. How can the height of a PDF be calculated from a dynamic content without loosing the flexibility of inserting images, headings, paragraphs etc. dynamically? And how can styles be kept flexible for future adjustments without having to re-program and re-calculate all heights?

TCPDF has a neat functionality which consists of creating a virtual document first which will be filled with the content. Once the virtual document is created, its measurements are taken in order to create the real PDF document. This allows to generate the PDF with the exact needed height, but without having to calculate the final height in advance!

Here is the code snippet:

// create virtual page with maximum height
$pdf->startTransaction();
$pdf->AddPage('P', array($totalW, 5*841.890)); // maximum height 5*A4
$h1 = $pdf->GetY();
$pdf->writeHTML($html, false, false, false, false, 'center');
$h2 = $pdf->GetY();
$totalH = $h2-$h1 + TOP_MARGIN + FOOTER_MARGIN;
$pdf = $pdf->rollbackTransaction();

// create page with correct height
$resolution = array($totalW, $totalH);
if ($totalW <= $totalH) {
$pdf->AddPage('P', $resolution);
}
else {
$pdf->AddPage('L', $resolution);
}

The Web Essentials team is happy to provide your custom PDF solution, be it an auto-generated invoice for an online shop, an itemised list from your database, or the styled print-version of your online calendar.

If you are a developer or TYPO3 enthusiast working with TCPDF, do not hesitate to get in touch with us, we like to connect with other developers and discuss solutions.


Passionate about web technologies or social business practices?

Web Essentials is hiring, web banner.

Related articles

PDF logo

2022 Year in Review: A Web Essentials Success Story

PDF logo

What does a Digital Transformation Consultant do?

PDF logo

Growing the Digital Economy in Cambodia

  • Agile
  • Innovation
  • ICT4D
  • Events
  • Technology
  • News
Newsletter Sign-Up
  •  
  •  

Agency Basel

Web Essentials GmbH 
Schuetzenrainweg 11
4125 Riehen
Switzerland

Tel.: +41 61 515 59 60
Email: info@web-essentials.co

Agency Phnom Penh

Web Essentials Co., Ltd
5th floor, Building #431 Street 230,
P.O. Box 889, Phnom Penh, Cambodia

Tel. KH: +855 23 996 604
Email: info@web-essentials.co

TYPO3 Silver Member



Neos Excellence Award winner 2017
We are recruiting: Visit our careers page!