Convert Figma logo to code with AI

tecnickcom logoTCPDF

Deprecated: PHP PDF library, superseded by tc-lib-pdf (https://github.com/tecnickcom/tc-lib-pdf)

4,545
1,585
4,545
1

Top Related Projects

11,154

HTML to PDF converter for PHP

4,699

PHP library generating PDF files from UTF-8 encoded HTML

7,573

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

11,154

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,699

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,573

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

Legacy PDF engine for PHP. Deprecated and maintained for existing integrations.

Latest Stable Version License Downloads Donate via PayPal

If TCPDF helps your business, please consider supporting development via PayPal.


Deprecation Notice

TCPDF is deprecated and in maintenance-only mode.

Active feature development has moved to tc-lib-pdf, the modern and modular successor.

For new projects, use tecnickcom/tc-lib-pdf. This repository remains available for legacy systems and critical compatibility fixes.

Migration Path

  • New projects: install tecnickcom/tc-lib-pdf.
  • Existing TCPDF users: keep TCPDF for current production workloads and migrate in phases.
  • Teams seeking modern architecture, Composer-first design, and stronger type-safety should prioritize tc-lib-pdf.

Why Migrate to tc-lib-pdf

  • Modern architecture: modular libraries and cleaner component boundaries improve maintainability.
  • Better extensibility: new features are easier to add without patching a monolithic legacy core.
  • Stronger tooling fit: modern package structure works better with static analysis, CI, and automated tests.
  • Lower long-term risk: reduces technical debt tied to legacy APIs and supports ongoing PHP ecosystem evolution.
  • Improved delivery speed: teams can implement and ship new PDF capabilities with less friction.

Migration still requires planning and regression checks to preserve rendering parity for existing documents.

Future Compatibility Possibility

As a long-term possibility, TCPDF could be refactored to use tc-lib-pdf internally as a backend while preserving a practical level of backward compatibility for existing TCPDF integrations.

This is not part of a committed roadmap and there is no guarantee it will happen. It is documented here only as a potential direction that may be evaluated in the future.


Overview

TCPDF is a pure-PHP library for generating PDF documents and barcodes directly in application code.

It has been widely used across many PHP stacks and still provides a complete feature set for text rendering, page composition, graphics, signatures, forms, and standards-oriented output.

Packagetecnickcom/tcpdf
AuthorNicola Asuni info@tecnick.com
LicenseGNU LGPL v3 (see LICENSE.TXT)
Websitehttp://www.tcpdf.org
Sourcehttps://github.com/tecnickcom/TCPDF

Features

Text & Fonts

  • UTF-8 Unicode and right-to-left (RTL) language support
  • TrueTypeUnicode, OpenTypeUnicode v1, TrueType, OpenType v1, Type1, and CID-0 fonts
  • Font subsetting
  • Text hyphenation, stretching, spacing, and rendering modes (fill/stroke/clipping)
  • Automatic line breaks, page breaks, and justification

Layout & Content

  • Standard and custom page formats, margins, and measurement units
  • XHTML + CSS rendering, JavaScript, and forms
  • Automatic headers and footers
  • Multi-column mode and no-write page regions
  • Bookmarks, named destinations, and table of contents
  • Automatic page numbering, page groups, move/delete pages, and undo transactions

Images, Graphics & Color

  • Native JPEG, PNG, and SVG support
  • Geometric drawing primitives and transformations
  • Support for GD image formats (GD, GD2, GD2PART, GIF, JPEG, PNG, BMP, XBM, XPM)
  • Additional formats via ImageMagick (when available)
  • JPEG/PNG ICC profiles, grayscale/RGB/CMYK/spot colors, and transparencies

Security, Standards & Advanced Output

  • Encryption up to 256-bit and digital signature certifications
  • PDF annotations (links, text, and file attachments)
  • 1D and 2D barcode support (including CODE 128, EAN/UPC, Datamatrix, QR Code, PDF417)
  • XObject templates and layers with object visibility controls
  • PDF/A-1b support

Requirements

  • PHP 7.1 or later
  • ext-curl

Optional extensions for richer output in some workflows: gd, zlib, imagick.


Third-Party Fonts

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

PHP metadata files under fonts are covered by the TCPDF license (GNU LGPL v3). They contain font metadata and can also be generated using TCPDF font utilities.

Original binary TTF files are renamed for compatibility and compressed with PHP gzcompress (the .z format).

PrefixSourceLicense
free*GNU FreeFontGNU GPL v3
pdfa*Derived from GNU FreeFontGNU GPL v3
dejavu*DejaVu FontsBitstream/DejaVu terms
ae*Arabeyes.orgGNU GPL v2

For full details, see the bundled notices in the corresponding subdirectories under fonts.


ICC Profile

TCPDF includes sRGB.icc from the Debian icc-profiles-free package.


Contact

Nicola Asuni info@tecnick.com