Giter VIP home page Giter VIP logo

actcpdfbundle's Introduction

ACTcpdfBundle

The ACTcpdfBundle integrates the TCPDF PHP library with Symfony. This means easy-to-implement and easy-to-ouptput PDF documents in your Symfony application.

Installation

Step 1: Download the Bundle

Open a command console, enter your project directory and execute the following command to download the latest stable version of this bundle:

composer require acucchieri/tcpdf-bundle

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Step 2: Enable the Bundle

Then, enable the bundle by adding the following line in the app/AppKernel.php file of your project:

// app/AppKernel.php
class AppKernel extends Kernel
{
    public function registerBundles()
    {
        $bundles = [
            // ...
            new AC\TcpdfBundle\ACTcpdfBundle(),
        ];

        // ...
    }
}

Usage

Use AC\TcpdfBundle\Pdf\PdfBuider to create your PDF document. This class extends TCPDF, see TCPDF documentation for more informations about PDF generation.

PDF Output

ACTcpdfBundle provide helpers to serve your PDF

Display the PDF in the browser

Return a Response with Content-Disposition: inline

$myPdf->inline('my-pdf.doc');

Download the PDF

Return a Response with Content-Disposition: attachment

$myPdf->download('my-pdf.doc');

Get the PDF as base64 mime multi-part email attachment (RFC 2045)

$myPdf->attachment('my-pdf.doc');

Save the PDF on a filesystem

$myPdf->save('/path/to/my-pdf.doc');

Output the PDF as string

$myPdf->toString();

MultiCell Helper

AC\TcpdfBundle\Pdf\PdfBuilder::addMultiCellRow($cells, $sameHeight, $nobr) allow you to build complex tables, based on MultiCell.

$cells is a multidimensional array. Each cell (array) contains :

  • The data (text or html)
  • The options. Available options :
  • height Cell height
  • width Cell width
  • border Draw the cell borders. Allowed values : 0 or 1. Default = 0
  • align Horz alignment. Allowed values : 'L' (left), 'C' (center), 'R' (right) or 'J' (justify). Default = 'T'
  • valign Vert alignment. Allowed values 'T' (top), 'M' (middle) or 'B' (bottom). Default = 'T'
  • fill Indicates if the cell background must be painted. true or false. Default = false
  • is_html Indicate if the data is html. See TCDPF doc for the supported tags. Default = false

$sameHeight If set to true all the row cells have the same height. Default = false.

$nobr If set to true the row is not break across 2 pages. Default = false.

Example

$data = [
  ['foo' => 'AAA', 'bar' => 123, 'baz' => '<b>text<b>'],
  ['foo' => 'BBB', 'bar' => 456, 'baz' => '<a href="https://domain.td">link</a>'],
  ['foo' => 'CCC', 'bar' => 789, 'baz' => '<ul><li>line 1</li><li>line 2</li></ul>'],
];

foreach ($data as $row) {
    $pdf->addRowCell([
      [$row['foo'], ['with' => 30]],
      [$row['bar'], ['width' => 40, 'align' => 'R']],
      [$row['baz'], ['width' => 50, 'is_html' => true]],
    ]);
}

License

This bundle is under the MIT license. See the complete license in the bundle

actcpdfbundle's People

Contributors

acucchieri avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.