PHP Classes

TCPDF Warper: Create PDF documents using TCPDF fluent interface

Recommend this page to a friend!
  Info   View files Example   Screenshots Screenshots   View files View files (74)   DownloadInstall with Composer Download .zip   Reputation   Support forum (1)   Blog    
Last Updated Ratings Unique User Downloads Download Rankings
2024-01-10 (2 months ago) RSS 2.0 feedNot yet rated by the usersTotal: 554 This week: 2All time: 5,487 This week: 96Up
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  
Name: Michal Kowalik <contact>
Classes: 3 packages by
Country: Poland Poland
Age: ???
All time rank: 233356 in Poland Poland
Week rank: 106 Up5 in Poland Poland Up
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  
  • tcpdfwarper-demo
  Files folder image Files  
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

  Files folder image Files  /  build  
File Role Description
  Accessible without login Plain text file generator.class.template.php Aux. generator class template
  Accessible without login Plain text file generator.config.php Aux. generator config
  Accessible without login Plain text file generator.php Aux. generator
  Accessible without login Plain text file generator.trait.template.php Aux. generator trait template
  Accessible without login Plain text file run_phpcs.sh Data phpcs command
  Accessible without login Plain text file travis.composer.json Data travis composer
  Accessible without login Plain text file travis.phpunit.xml Data travis phpunit

  Files folder image Files  /  examples  
File Role Description
  Accessible without login Plain text file example-01.php Example Example script 01
  Accessible without login Image file image-01.jpg Data image for example 01

  Files folder image Files  /  src  
File Role Description
Files folder imageorg (1 directory)

  Files folder image Files  /  src  /  org  
File Role Description
Files folder imagemajkel (1 directory)

  Files folder image Files  /  src  /  org  /  majkel  
File Role Description
Files folder imagetcpdfwarper (18 files, 1 directory)

  Files folder image Files  /  src  /  org  /  majkel  /  tcpdfwarper  
File Role Description
Files folder imagegenerator (7 files)
  Plain text file AbstractException.php Class Exception base class
  Plain text file AbstractOp.php Class Call base class
  Plain text file Barcode1dOp.php Class write1DBarcode
  Plain text file Barcode2dOp.php Class write2DBarcode
  Plain text file CellOp.php Class Cell call class
  Plain text file HtmlCellOp.php Class writeHTMLCell
  Plain text file HtmlOp.php Class writeHTML
  Plain text file ImageEpsOp.php Class ImageEps
  Plain text file ImageOp.php Class Image call class
  Plain text file ImageSvgOp.php Class ImageSvg
  Plain text file MissingArgException.php Class Missing argument exception
  Plain text file MissingMethodException.php Class Missing method exception
  Plain text file MultiCellOp.php Class Multicell call class
  Plain text file TCPDFWarper.php Class The warper
  Plain text file TCPDFWarperTrait.php Class Warper trait
  Plain text file TextOp.php Class Text call class
  Plain text file Utils.php Class Utility functions
  Plain text file WriteOp.php Class Write

  Files folder image Files  /  src  /  org  /  majkel  /  tcpdfwarper  /  generator  
File Role Description
  Accessible without login Plain text file Argument.php Aux. generator
  Accessible without login Plain text file ClassDefinition.php Aux. generator
  Accessible without login Plain text file ClassMetaMethod.php Aux. generator
  Accessible without login Plain text file ConfigItem.php Aux. generator
  Accessible without login Plain text file ConfigMetaMethod.php Aux. generator
  Accessible without login Plain text file Generator.php Aux. generator
  Accessible without login Plain text file GeneratorException.php Aux. generator

  Files folder image Files  /  style  
File Role Description
  Accessible without login Plain text file ruleset.xml Data style rulset

  Files folder image Files  /  tests  
File Role Description
Files folder imageorg (1 directory)
Files folder imagereport (1 file)
  Accessible without login Plain text file bootstrap.php Test tests

  Files folder image Files  /  tests  /  org  
File Role Description
Files folder imagemajkel (1 directory)

  Files folder image Files  /  tests  /  org  /  majkel  
File Role Description
Files folder imagetcpdfwarper (19 files, 1 directory)

  Files folder image Files  /  tests  /  org  /  majkel  /  tcpdfwarper  
File Role Description
Files folder imagegenerator (7 files, 1 directory)
  Accessible without login Plain text file AbstractOpTest.php Test tests
  Accessible without login Plain text file AbstractTestCase.php Test tests
  Accessible without login Plain text file Barcode1dOpTest.php Test test write1DBarcode
  Accessible without login Plain text file Barcode2dOpTest.php Test test write2DBarcode
  Accessible without login Plain text file CellOpTest.php Test tests
  Accessible without login Plain text file DummyTcpdf.php Test dummy test tcpdf
  Accessible without login Plain text file HtmlCellOpTest.php Test test writeHTMLCell
  Accessible without login Plain text file HtmlOpTest.php Test test writeHTML
  Accessible without login Plain text file ImageEpsOpTest.php Test test ImageEps
  Accessible without login Plain text file ImageOpTest.php Test tests
  Accessible without login Plain text file ImageSvgOpTest.php Test test ImageSvg
  Accessible without login Plain text file MissingArgExceptionTest.php Test tests
  Accessible without login Plain text file MissingMethodExceptionTest.php Test tests
  Accessible without login Plain text file MulticellOpTest.php Test tests
  Accessible without login Plain text file OpTestAbstract.php Test tests
  Accessible without login Plain text file TCPDFWarperTest.php Test tests
  Accessible without login Plain text file TextOpTest.php Test tests
  Accessible without login Plain text file UtilsTest.php Test Utility functions tests
  Accessible without login Plain text file WriteOpTest.php Test test Write

  Files folder image Files  /  tests  /  org  /  majkel  /  tcpdfwarper  /  generator  
File Role Description
Files folder imagedata (4 files)
  Accessible without login Plain text file ClassDefinitionMock.php Aux. test generator
  Accessible without login Plain text file ClassDefinitionSampleClass.php Aux. test generator
  Accessible without login Plain text file ClassDefinitionTest.php Test test generator
  Accessible without login Plain text file ConfigItemTest.php Test test generator
  Accessible without login Plain text file ConfigMetaMethodTest.php Test test generator
  Accessible without login Plain text file FuncMock.php Aux. test generator
  Accessible without login Plain text file GeneratorTest.php Test test generator

  Files folder image Files  /  tests  /  org  /  majkel  /  tcpdfwarper  /  generator  /  data  
File Role Description
  Accessible without login Plain text file class.template.php Aux. test generator
  Accessible without login Plain text file config.invalid.php Aux. test generator
  Accessible without login Plain text file config.test.php Aux. test generator
  Accessible without login Plain text file trait.template.php Aux. test generator

  Files folder image Files  /  tests  /  report  
File Role Description
  Accessible without login Plain text file .gitignore Data .gitignore

 Version Control Unique User Downloads Download Rankings  
 98%
Total:554
This week:2
All time:5,487
This week:96Up