Convert Figma logo to code with AI

tecnickcom logoTCPDF

Official clone of PHP library to generate PDF documents and barcodes

4,143
1,509
4,143
351

Top Related Projects

10,446

HTML to PDF converter for PHP

4,355

PHP library generating PDF files from UTF-8 encoded HTML

7,206

A pure PHP library for reading and writing word processing documents

A DOMPDF Wrapper for Laravel

A slim PHP wrapper around wkhtmltopdf with an easy to use and clean OOP interface

Quick Overview

TCPDF is a popular PHP library for generating PDF documents. It provides a comprehensive set of tools and functions to create complex PDF files with features like text formatting, images, tables, and more. TCPDF is widely used in web applications and content management systems for generating reports, invoices, and other document types.

Pros

  • Extensive feature set for creating complex PDF documents
  • Supports various fonts, including Unicode and right-to-left languages
  • Includes barcode generation capabilities
  • Well-documented with many examples and tutorials

Cons

  • Large codebase, which can lead to slower performance compared to simpler PDF libraries
  • Steep learning curve for beginners due to its extensive functionality
  • Some users report occasional issues with text alignment and positioning
  • Limited support for newer PHP versions (primarily targets PHP 5.x)

Code Examples

  1. Creating a simple PDF document:
require_once('tcpdf/tcpdf.php');

$pdf = new TCPDF();
$pdf->AddPage();
$pdf->SetFont('helvetica', '', 12);
$pdf->Cell(0, 10, 'Hello, World!', 0, 1);
$pdf->Output('hello_world.pdf', 'F');
  1. Adding an image to a PDF:
$pdf->Image('path/to/image.jpg', 10, 10, 90, 0, 'JPG');
  1. Creating a table in the PDF:
$html = '
<table border="1">
    <tr>
        <th>Header 1</th>
        <th>Header 2</th>
    </tr>
    <tr>
        <td>Row 1, Cell 1</td>
        <td>Row 1, Cell 2</td>
    </tr>
</table>';

$pdf->writeHTML($html, true, false, true, false, '');

Getting Started

  1. Install TCPDF using Composer:

    composer require tecnickcom/tcpdf
    
  2. Create a new PHP file and include the TCPDF library:

    require_once('vendor/autoload.php');
    
  3. Create a new TCPDF instance and start generating your PDF:

    $pdf = new TCPDF();
    $pdf->AddPage();
    $pdf->SetFont('helvetica', '', 12);
    $pdf->Cell(0, 10, 'Your PDF content goes here', 0, 1);
    $pdf->Output('output.pdf', 'F');
    

This will create a basic PDF file named 'output.pdf' in the same directory as your PHP script.

Competitor Comparisons

10,446

HTML to PDF converter for PHP

Pros of dompdf

  • Easier to use for converting HTML/CSS to PDF
  • Better support for modern CSS features
  • More actively maintained with frequent updates

Cons of dompdf

  • Slower performance for large documents
  • Less extensive feature set compared to TCPDF
  • May have compatibility issues with complex layouts

Code Comparison

dompdf:

require_once 'dompdf/autoload.inc.php';
$dompdf = new Dompdf();
$dompdf->loadHtml($html);
$dompdf->render();
$dompdf->stream("document.pdf");

TCPDF:

require_once('tcpdf/tcpdf.php');
$pdf = new TCPDF();
$pdf->AddPage();
$pdf->writeHTML($html);
$pdf->Output('document.pdf', 'I');

Both libraries offer straightforward ways to generate PDFs from HTML, but dompdf's approach is slightly more concise. TCPDF provides more granular control over the PDF creation process, which can be beneficial for complex documents but may require more code for simple tasks.

dompdf is generally easier to use for basic HTML-to-PDF conversion, while TCPDF offers more advanced features and better performance for large documents. The choice between the two depends on the specific requirements of your project, such as document complexity, performance needs, and desired CSS support.

4,355

PHP library generating PDF files from UTF-8 encoded HTML

Pros of mpdf

  • Better support for CSS and HTML5, allowing for easier styling and layout
  • Faster rendering speed, especially for complex documents
  • More active development and community support

Cons of mpdf

  • Larger file size and memory footprint
  • Less extensive documentation compared to TCPDF
  • Fewer built-in features for advanced PDF manipulation

Code Comparison

mpdf:

$mpdf = new \Mpdf\Mpdf();
$mpdf->WriteHTML('<h1>Hello World</h1>');
$mpdf->Output('document.pdf', 'F');

TCPDF:

$pdf = new TCPDF();
$pdf->AddPage();
$pdf->SetFont('helvetica', '', 12);
$pdf->Cell(0, 10, 'Hello World', 0, 1);
$pdf->Output('document.pdf', 'F');

Both libraries offer PHP-based PDF generation, but mpdf focuses on HTML-to-PDF conversion, while TCPDF provides more low-level PDF creation methods. mpdf's approach is generally more intuitive for web developers familiar with HTML and CSS, while TCPDF offers finer control over PDF elements and structure.

7,206

A pure PHP library for reading and writing word processing documents

Pros of PHPWord

  • Specialized for creating and manipulating Word documents
  • Supports a wider range of Word-specific features and formatting options
  • More intuitive API for working with Word document structures

Cons of PHPWord

  • Limited to Word document generation, less versatile than TCPDF
  • May have a steeper learning curve for users familiar with PDF-centric libraries
  • Potentially slower performance when dealing with large documents

Code Comparison

PHPWord:

$phpWord = new \PhpOffice\PhpWord\PhpWord();
$section = $phpWord->addSection();
$section->addText('Hello World!');
$writer = \PhpOffice\PhpWord\IOFactory::createWriter($phpWord, 'Word2007');
$writer->save('helloWorld.docx');

TCPDF:

$pdf = new TCPDF();
$pdf->AddPage();
$pdf->SetFont('helvetica', '', 12);
$pdf->Cell(0, 10, 'Hello World!');
$pdf->Output('helloWorld.pdf', 'F');

Both libraries offer straightforward ways to create documents, but PHPWord is tailored for Word documents, while TCPDF focuses on PDF generation. PHPWord provides more Word-specific features, while TCPDF offers greater flexibility for creating various types of PDF documents.

A DOMPDF Wrapper for Laravel

Pros of laravel-dompdf

  • Seamless integration with Laravel framework
  • Easy to use with Laravel's Facade system
  • Supports HTML5 and CSS3 for more modern styling options

Cons of laravel-dompdf

  • Limited support for complex layouts and advanced PDF features
  • May have performance issues with large or complex documents
  • Less frequent updates compared to TCPDF

Code Comparison

laravel-dompdf:

use Barryvdh\DomPDF\Facade\Pdf;

$pdf = Pdf::loadView('pdf.invoice', $data);
return $pdf->download('invoice.pdf');

TCPDF:

$pdf = new TCPDF();
$pdf->AddPage();
$pdf->writeHTML($html, true, false, true, false, '');
$pdf->Output('document.pdf', 'D');

Both libraries offer straightforward ways to generate PDFs, but laravel-dompdf provides a more Laravel-centric approach with its Facade. TCPDF offers more granular control over the PDF creation process, which can be beneficial for complex documents but may require more code for basic tasks.

A slim PHP wrapper around wkhtmltopdf with an easy to use and clean OOP interface

Pros of phpwkhtmltopdf

  • Renders HTML/CSS accurately, including complex layouts and modern web features
  • Supports JavaScript execution, allowing dynamic content generation
  • Faster PDF generation for complex documents with many elements

Cons of phpwkhtmltopdf

  • Requires external dependencies (wkhtmltopdf binary)
  • Less control over low-level PDF structure and metadata
  • May have compatibility issues with some server environments

Code Comparison

TCPDF:

$pdf = new TCPDF();
$pdf->AddPage();
$pdf->writeHTML($html);
$pdf->Output('document.pdf', 'F');

phpwkhtmltopdf:

$pdf = new Pdf($html);
$pdf->saveAs('document.pdf');

TCPDF offers more granular control over PDF creation, while phpwkhtmltopdf provides a simpler API for converting HTML to PDF. TCPDF is better suited for generating PDFs from scratch or with precise layout requirements, whereas phpwkhtmltopdf excels at converting existing web pages or complex HTML/CSS layouts into PDFs with high fidelity.

Choose TCPDF for fine-grained control and server-side PDF generation without external dependencies. Opt for phpwkhtmltopdf when dealing with modern web layouts or when accurate HTML/CSS rendering is crucial.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

TCPDF

PHP PDF Library

Donate via PayPal Please consider supporting this project by making a donation via PayPal

NOTE

A new version of this library is under development at https://github.com/tecnickcom/tc-lib-pdf and as a consequence this library is in support only mode.

Description

PHP library for generating PDF documents on-the-fly.

Main Features:

  • no external libraries are required for the basic functions;
  • all standard page formats, custom page formats, custom margins and units of measure;
  • UTF-8 Unicode and Right-To-Left languages;
  • TrueTypeUnicode, OpenTypeUnicode v1, TrueType, OpenType v1, Type1 and CID-0 fonts;
  • font subsetting;
  • methods to publish some XHTML + CSS code, Javascript and Forms;
  • images, graphic (geometric figures) and transformation methods;
  • supports JPEG, PNG and SVG images natively, all images supported by GD (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM) and all images supported via ImagMagick (http://www.imagemagick.org/script/formats.php)
  • 1D and 2D barcodes: CODE 39, ANSI MH10.8M-1983, USD-3, 3 of 9, CODE 93, USS-93, Standard 2 of 5, Interleaved 2 of 5, CODE 128 A/B/C, 2 and 5 Digits UPC-Based Extension, EAN 8, EAN 13, UPC-A, UPC-E, MSI, POSTNET, PLANET, RMS4CC (Royal Mail 4-state Customer Code), CBC (Customer Bar Code), KIX (Klant index - Customer index), Intelligent Mail Barcode, Onecode, USPS-B-3200, CODABAR, CODE 11, PHARMACODE, PHARMACODE TWO-TRACKS, Datamatrix, QR-Code, PDF417;
  • JPEG and PNG ICC profiles, Grayscale, RGB, CMYK, Spot Colors and Transparencies;
  • automatic page header and footer management;
  • document encryption up to 256 bit and digital signature certifications;
  • transactions to UNDO commands;
  • PDF annotations, including links, text and file attachments;
  • text rendering modes (fill, stroke and clipping);
  • multiple columns mode;
  • no-write page regions;
  • bookmarks, named destinations and table of content;
  • text hyphenation;
  • text stretching and spacing (tracking);
  • automatic page break, line break and text alignments including justification;
  • automatic page numbering and page groups;
  • move and delete pages;
  • page compression (requires php-zlib extension);
  • XOBject Templates;
  • Layers and object visibility.
  • PDF/A-1b support.

Third party fonts:

This library may include third party font files released with different licenses.

All the PHP files on the fonts directory are subject to the general TCPDF license (GNU-LGPLv3), they do not contain any binary data but just a description of the general properties of a particular font. These files can be also generated on the fly using the font utilities and TCPDF methods.

All the original binary TTF font files have been renamed for compatibility with TCPDF and compressed using the gzcompress PHP function that uses the ZLIB data format (.z files).

The binary files (.z) that begins with the prefix "free" have been extracted from the GNU FreeFont collection (GNU-GPLv3). The binary files (.z) that begins with the prefix "pdfa" have been derived from the GNU FreeFont, so they are subject to the same license. For the details of Copyright, License and other information, please check the files inside the directory fonts/freefont-20120503 Link : http://www.gnu.org/software/freefont/

The binary files (.z) that begins with the prefix "dejavu" have been extracted from the DejaVu fonts 2.33 (Bitstream) collection. For the details of Copyright, License and other information, please check the files inside the directory fonts/dejavu-fonts-ttf-2.33 Link : http://dejavu-fonts.org

The binary files (.z) that begins with the prefix "ae" have been extracted from the Arabeyes.org collection (GNU-GPLv2). Link : http://projects.arabeyes.org/

ICC profile:

TCPDF includes the sRGB.icc profile from the icc-profiles-free Debian package: https://packages.debian.org/source/stable/icc-profiles-free

Developer(s) Contact