PHP Classes

TCPDF Warper: Create PDF documents using TCPDF fluent interface

Recommend this page to a friend!
  Info   Example   Screenshots   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 565 All time: 5,414 This week: 52Up
Version License PHP version Categories
tcpdf-warper 0.2.13Custom (specified...5.4PHP 5, Files and Folders, Printing, L..., T...
Description 

Author

This class can create PDF documents using fluent interface around the TCPDF library.

It provides several classes and traits that can be used to compose and render PDF documents using the TCPDF package.

Currently it provides wrappers for adding text, images, barcodes and cell elements.

Picture of Michal Kowalik
  Performance   Level  
Innovation award
Innovation award
Nominee: 1x

 

Recommendations

What is the best PHP pdf creation class?
CREATE PDF

Extract database table data
Get database content into a PDF file

Example

<?php
/**
 * Based on TCPDF example 001
 * See: http://www.tcpdf.org/examples.php
 * User: Micha? (majkel) Kowalik <maf.michal@gmail.com>
 * Date: 1/8/2015
 * Time: 00:00
 */

namespace org\majkel;

chdir(__DIR__);

require_once
'../vendor/autoload.php';

class
PDF extends \TCPDF {
    use
tcpdfwarper\TCPDFWarperTrait;
}

$pdf = new PDF(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
$pdf->SetCreator(PDF_CREATOR);
$pdf->SetAuthor('Nicola Asuni');
$pdf->SetTitle('TCPDF Example 001');
$pdf->SetSubject('TCPDF Tutorial');
$pdf->SetKeywords('TCPDF, PDF, example, test, guide');
$pdf->SetMargins(PDF_MARGIN_LEFT, PDF_MARGIN_TOP, PDF_MARGIN_RIGHT);
$pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
$pdf->SetFooterMargin(PDF_MARGIN_FOOTER);
$pdf->SetAutoPageBreak(true, PDF_MARGIN_BOTTOM);
$pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);
$pdf->setFontSubsetting(true);
$pdf->SetFont('dejavusans', '', 14, '', true);

$pdf->AddPage();

$html = <<<EOD
<h1>Welcome to <a href="http://www.tcpdf.org"
  style="text-decoration:none;background-color:#CC0000;">
  &nbsp;<span style="color:black;">TC</span><span style="color:white;">PDF</span>&nbsp;</a>!
</h1>
<i>This is the first example of TCPDF library.</i>
<p>This text is printed using the <i>writeHTMLCell()</i> method but you can also use:
  <i>Multicell(),writeHTML(), Write(), Cell() and Text()</i>.</p>
<p>Please check the source code documentation and other examples for further information.</p>
<p style="color:#CC0000;">TO IMPROVE AND EXPAND TCPDF I NEED YOUR SUPPORT, PLEASE
  <a href="http://sourceforge.net/donate/index.php?group_id=128076">MAKE A DONATION!</a>
</p>
<br/>
EOD;

$pdf->buildMulticell()
        ->
setSize(0, 0)
        ->
setTxt($html)
        ->
setIshtml(true)
        ->
render();

$pdf->buildImage()
        ->
setFile('image-01.jpg')
        ->
setPalign('C')
        ->
setLink('https://github.com/majkel89/tcpdf-warper')
        ->
render();

$pdf->Output('example_001.pdf', 'I');


Details

TCPDF Warper

Build Status SensioLabsInsight Code Climate Test Coverage Latest Stable Version Latest Unstable Version PHP Version License

Installation

 composer require tecnick.com/tcpdf       ### or any TCPDF library
 composer require org.majkel/tcpdfwarper

About

Provides fluent statement builders for TCPDF library.

Mine intention was to make calls to methods, with many arguments, clearer and more maintainable.

// instead of
$pdf = new \TCPDF();
$pdf->Image($file, $x, $y, $w, $h, '', '', '', true, 300, '',
         true, false, 10, true, false, false, true, $altimgs);

// you can use this
$pdf = new \org\majkel\tcpdfwarper\TCPDFWarper();
$pdf->buildImage()->setFile($file)
    ->setPos(20, 20)->setSize(64, 64)
    ->setAlt(true)->setAltImgs($altimgs)
    ->render();

No more hassle with remembering which argument is which or hardcodeing long list of parameters just to change last one of them.

Following methods are supported

* Cell (buildCell) * Multicell (buildMulticell) * Image (buildImage) * ImageSvg (buildImageSvg) * ImageEps (buildImageEps) * Text (buildText) * writeHTML (buildHtml) * writeHTMLCell (buildHtmlCell) * write1DBarcode (buildBarcode1d) * write2DBarcode (buildBarcode2d) * Write (buildWrite)

If you are using some kind of fork of TCPDF, you can write your own warper. Every statement builder allows you to inject $tcpdf object.

 $image = new \org\majkel\tcpdfwarper\ImageOp($tcpdf);
 $image->setFile($file)
     ->setPos(20, 20)->setSize(64, 64)
     ->render();

Features

- Fully unit tested - Full code coverage - Code completion friendly (including documentation) - Tested against multiple php versions (5.4 - 7.0, hhvm) - Tested against multiple TCPDF libraries (see travis)

License

The MIT License (MIT)

Copyright (c) 2015 Micha? (majkel) Kowalik

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Bitdeli Badge


Screenshots (1)  
  • tcpdfwarper-demo
  Files folder image Files (75)  
File Role Description
Files folder imagebuild (7 files)
Files folder imageexamples (2 files)
Files folder imagesrc (1 directory)
Files folder imagestyle (1 file)
Files folder imagetests (1 file, 2 directories)
Accessible without login Plain text file .codeclimate.yml Data Code Climate confguration
Accessible without login Plain text file .travis.yml Data travis config
Accessible without login Plain text file composer.json Data composer config
Accessible without login Plain text file composer.lock Data composer lock
Accessible without login Plain text file LICENSE.md Lic. LICENSE
Accessible without login Plain text file phpunit.xml Data phpunit conf
Accessible without login Plain text file README.md Doc. readme

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 98%
Total:565
This week:0
All time:5,414
This week:52Up