.. ================================================== .. FOR YOUR INFORMATION .. -------------------------------------------------- .. -*- coding: utf-8 -*- with BOM. .. include:: ../../Includes.txt Advanced Customization ---------------------- To completely customize the PDF creation you have the options to write your own ViewHelper or provide your own PDF class. If you feel like your custom ViewHelper might be useful for everybody, feel free to create a pull request! Create your own ViewHelper ^^^^^^^^^^^^^^^^^^^^^^^^^^ Creating your own ViewHelper might be necessary if you need access to a TCPDF method that is not yet available through the implemented ViewHelpers or if you have a complex layout to realise. When writing your own ViewHelper you have the options to extend ``AbstractContentElementViewHelper`` or ``AbstractPDFViewHelper``. If your ViewHelper will add some content to the PDF (e.g. ``TextViewHelper`` or ``LineViewHelper``), you should extend ``AbstractContentElementViewHelper`` in order to inherit its position properties and allow the header and footer ViewHelpers to work properly. If your ViewHelper does not add content (e.g. ``GetPosXViewHelper`` or ``PageBreakViewHelper``) you can directly extend ``AbstractPDFViewHelper``. Within your ViewHelper you have full access to the public API of TCPDF using ``$this->getPDF()``. Please see the TCPDF examples in order to see what you can do with it: https://tcpdf.org/examples/ The following example shows a ViewHelper that could be used to render a TCPDF barcode. *PHP* :: , Bithost GmbH * Esteban Gehring , Bithost GmbH * * All rights reserved * * This script is part of the TYPO3 project. The TYPO3 project is * free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * The GNU General Public License can be found at * http://www.gnu.org/copyleft/gpl.html. * * This script is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * This copyright notice MUST APPEAR in all copies of the script! ***/ use Bithost\Pdfviewhelpers\ViewHelpers\AbstractContentElementViewHelper; /** * BarcodeViewHelper * * @author Markus Mächler , Esteban Gehring */ class BarcodeViewHelper extends AbstractContentElementViewHelper { /** * @param string $title * @param string $code * @param string $type * * @return void */ public function render($title, $code, $type) { $style = [ 'position' => '', 'align' => 'C', 'stretch' => FALSE, 'fitwidth' => TRUE, 'cellfitalign' => '', 'border' => TRUE, 'hpadding' => 'auto', 'vpadding' => 'auto', 'fgcolor' => [0,0,0], 'bgcolor' => FALSE, 'text' => TRUE, 'font' => 'helvetica', 'fontsize' => 8, 'stretchtext' => 4 ]; $this->getPDF()->SetFontSize($this->settings['generalText']['fontSize']); $this->getPDF()->Cell(0, 0, $title, 0, 1); $this->getPDF()->write1DBarcode($code, $type, '', '', '', 18, 0.4, $style, 'N'); } } *Fluid* :: {namespace pdf=Bithost\Pdfviewhelpers\ViewHelpers} {namespace you=Vendor\YourExtension\ViewHelpers} Extend BasePDF class ^^^^^^^^^^^^^^^^^^^^ You can provide your own PDF class in the TypoScript settings in order to customize its behaviour as you want. Your own PDF class is required to extend ``Bithost\Pdfviewhelpers\Model\BasePDF``. *TypoScript* :: plugin.tx_pdfviewhelpers.settings { config { class = Vendor\YourExtension\Model\MyPDF } } *PHP* :: , Bithost GmbH * Esteban Gehring , Bithost GmbH * * All rights reserved * * This script is part of the TYPO3 project. The TYPO3 project is * free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * The GNU General Public License can be found at * http://www.gnu.org/copyleft/gpl.html. * * This script is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * This copyright notice MUST APPEAR in all copies of the script! ***/ use TYPO3\CMS\Core\Utility\ExtensionManagementUtility; /** * MyPDF * * @author Markus Mächler , Esteban Gehring */ class MyPDF extends \Bithost\Pdfviewhelpers\Model\BasePDF { /** * @return void */ public function __construct($orientation='P', $unit='mm', $format='A4', $unicode=true, $encoding='UTF-8', $diskcache=false, $pdfa=false) { $myFormat = 'A3'; parent::__construct($orientation, $unit, $myFormat, $unicode, $encoding, $diskcache, $pdfa); } /** * @return void */ public function basePdfHeader() { $extPath = ExtensionManagementUtility::extPath('pdfviewhelpers'); $address = "Bithost GmbH \nMilchubckstrasse 83 \nCH-8057 Zürich \n\nhallo@bithost.ch \n044 585 28 20 \n\nwww.bithost.ch"; $this->SetTextColor(140, 140, 140); $this->SetFontSize(11); $this->Image($extPath . 'Resources/Public/Examples/BasicUsage/logo.png', 15, 15, 56, 24, '', '', '', FALSE, 300, '', FALSE, FALSE, 0, FALSE, FALSE, FALSE, FALSE); $this->MultiCell(null, null, $address, 0, 'R', FALSE, 1, 0, 45, TRUE, 0, FALSE, TRUE, 0, 'T', FALSE); } /** * @return void */ public function basePdfFooter() { $this->SetY(-20); $this->SetDrawColor(140, 140, 140); $this->Line(15, $this->y, $this->w - 15, $this->y); $this->SetY(-17); $this->SetTextColor(140, 140, 140); $this->SetFontSize(11); $this->Cell($this->w - 15, 10, 'Page '.$this->getAliasNumPage() . ' of '.$this->getAliasNbPages(), 0, false, 'C', 0, '', 1, false, 'T', 'M'); } }