Developed with love by KnpLabs Hire us for your project!
106

WhiteOctoberTCPDFBundle

by sampart

A bundle to facilitate using TCPDF for PDF generation in Symfony applications

This project is not actively maintained. For Symfony 3.4 and above, you may wish to use this fork.

WhiteOctoberTCPDFBundle

This bundle facilitates easy use of the TCPDF PDF generation library in
Symfony2 applications.

Installation

Step 1: Setup Bundle and dependencies

composer require whiteoctober/tcpdf-bundle

Version constraining (optional)

By default, this bundle does not constrain the version of TCPDF that composer installs.
(An explanation of this unusual decision is here).
This means that a composer update could update to a new major version of TCPDF.
Since this bundle is only a thin wrapper around TCPDF, you can normally do such an upgrade without issue.

However, if you do wish to constrain the TCPDF version, find out what version you currently have installed with:

composer show tecnickcom/tcpdf

And amend your project's composer.json to add a TCPDF version constraint in the requires section.
For example, if TCPDF version 6.2.17 was installed, "tecnickcom/tcpdf": "^6.2.17" will allow anything < 7 when upgrading.

Step 2: Enable the bundle in the kernel

Add the bundle to the registerBundles() method in your kernel:

In Symfony < 4:

// app/AppKernel.php
<?php

public function registerBundles()
{
    $bundles = array(
        // ...
        new WhiteOctober\TCPDFBundle\WhiteOctoberTCPDFBundle(),
    );
}

In Symfony 4:

// config/bundles.php
return [
    // ...
    WhiteOctober\TCPDFBundle\WhiteOctoberTCPDFBundle::class => ['all' => true],
    // ...
];

(This project is not yet configured with Symfony Flex, so this change to config/bundles.php won't be done automatically.)

If you want to do service autowiring, you'll need to add an alias for the service:

# app/config/services.yml (Symfony 3)
# config/services.yaml (Symfony 4)
services:
    # ...

    # the `white_october.tcpdf` service will be injected when a
    # `WhiteOctober\TCPDFBundle\Controller\TCPDFController` type-hint is detected
    WhiteOctober\TCPDFBundle\Controller\TCPDFController: '@white_october.tcpdf'

Using TCPDF

You can obtain the white_october.tcpdf service from the container,
and then create a new TCPDF object via the service:

$pdfObj = $container->get("white_october.tcpdf")->create();

From hereon in, you are using a TCPDF object to work with as normal.

Configuration

Configuration values

You can pass parameters to TCPDF like this:

# app/config/config.yml (Symfony < 4)
# config/packages/white_october_tcpdf.yaml (Symfony 4)
white_october_tcpdf:
    tcpdf:
        k_title_magnification: 2

You can see the default parameter values in
WhiteOctober\TCPDFBundle\DependencyInjection\Configuration::addTCPDFConfig.

If you want, you can use TCPDF's own defaults instead:

white_october_tcpdf:
    tcpdf:
        k_tcpdf_external_config: false  # the values set by this bundle will be ignored

Using a custom class

If you want to use your own custom TCPDF-based class, you can use
the class parameter in your configuration:

# app/config/config.yml (Symfony < 4)
# config/packages/white_october_tcpdf.yaml (Symfony 4)
white_october_tcpdf:
    class: 'Acme\MyBundle\MyTCPDFClass'

The class must extend from the TCPDF class; an exception will be
thrown if this is not the case.

License

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

Resources/meta/LICENSE

This project was originally located at https://github.com/whiteoctober/WhiteOctoberTCPDFBundle

Copyright (c) 2012 White October Ltd

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.
white_october_tcpdf:
file: %kernel.root_dir%/../vendor/tecnickcom/tcpdf/tcpdf.php
class: TCPDF
tcpdf:
k_path_url: %kernel.root_dir%/../vendor/tecnickcom/tcpdf/
k_path_main: %kernel.root_dir%/../vendor/tecnickcom/tcpdf/
k_path_fonts: %kernel.root_dir%/../vendor/tecnickcom/tcpdf/fonts/
k_path_cache: %kernel.cache_dir%/tcpdf
k_path_url_cache: %kernel.cache_dir%/tcpdf
k_path_images: %kernel.root_dir%/../vendor/tecnickcom/tcpdf/examples/images/
k_blank_image: %kernel.root_dir%/../vendor/tecnickcom/tcpdf/examples/images/_blank.png
k_cell_height_ratio: 1.25
k_title_magnification: 1.3
k_small_ratio: 0.66666666666667
k_thai_topchars: true
k_tcpdf_calls_in_html: false
k_tcpdf_external_config: true
k_tcpdf_throw_exception_error: true
head_magnification: 1.1
pdf_page_format: A4
pdf_page_orientation: P
pdf_creator: TCPDF
pdf_author: TCPDF
pdf_header_title:
pdf_header_string:
pdf_header_logo:
pdf_header_logo_width:
pdf_unit: mm
pdf_margin_header: 5
pdf_margin_footer: 10
pdf_margin_top: 27
pdf_margin_bottom: 25
pdf_margin_left: 15
pdf_margin_right: 15
pdf_font_name_main: helvetica
pdf_font_size_main: 10
pdf_font_name_data: helvetica
pdf_font_size_data: 8
pdf_font_monospaced: courier
pdf_image_scale_ratio: 1.25
  • Remove contribution information, preparing to archive
    By web-flow, 9 days ago
  • Add note about fork for Symfony >= 3.4
    By sampart, 11 months ago
  • Add note about looking for maintainers
    By Sam Partington, 1 year ago
  • Merge pull request #55 from SvetlinStaev/master
    By web-flow, 1 year ago
  • Removed children call which is already used below
    By SvetlinStaevWorldstores, 1 year ago
  • Added compatibility to Symfony 4.2+
    By SvetlinStaevWorldstores, 1 year ago
  • Merge pull request #54 from whiteoctober/readme-version-constraint
    By web-flow, 1 year ago
  • Add note about constraining TCPDF version.
    By Sam Partington, 1 year ago
  • Added setting constant for throwing exceptions (TCPDF) instead of a die (#52)
    By Sam Partington, 2 years ago
  • Merge pull request #51 from whiteoctober/composer-json-fix
    By web-flow, 2 years ago
  • Remove erroneous trailing comma in composer.json
    By Sam Partington, 2 years ago
  • Merge pull request #50 from samnela/change-psr-autoload
    By web-flow, 2 years ago
  • Moved to psr-4
    By samnela, 2 years ago
  • Merge pull request #49 from whiteoctober/document-config
    By web-flow, 2 years ago
  • Merge pull request #45 from epieterman/master
    By web-flow, 2 years ago
  • Document how to pass configuration values to TCPDF
    By Sam Partington, 2 years ago
  • Merge pull request #48 from whiteoctober/autowiring-doc
    By web-flow, 2 years ago
  • Add note about enabling service autowiring
    By Sam Partington, 2 years ago
  • Merge pull request #47 from whiteoctober/symfony-4-install
    By web-flow, 2 years ago
  • Add instructions about configuring bundle on Symfony 4
    By Sam Partington, 2 years ago
  • changed logic in function boot that all config parameters can be loaded
    By Erik Pieterman, 2 years ago
  • Merge pull request #42 from whiteoctober/doc-autoload
    By web-flow, 3 years ago
  • Remove autoload step from install guide; composer handles that now
    By Sam Partington, 3 years ago
  • Merge pull request #40 from whiteoctober/code-of-conduct
    By web-flow, 3 years ago
  • Add "contributing" section to README, plus code-of-conduct
    By Sam Partington, 3 years ago
  • Merge pull request #39 from whiteoctober/gitignore
    By web-flow, 3 years ago
  • Merge pull request #32 from DjangoFR/issue-28
    By web-flow, 3 years ago
  • Add basic .gitignore file
    By Sam Partington, 3 years ago
  • Merge pull request #35 from jacobmaster/patch-2
    By richsage, 5 years ago
  • Updated configuration paths after updated tcpdf package name
    By jacobmaster, 5 years ago