PDF ViewHelpers

Classification

pdfviewhelpers

Version

3.1

Language

en

Description

Various Fluid ViewHelpers that help you to make any Fluid Template into a PDF document.

Keywords

pdf, generation, generator, fluid, viewhelper, fpdi, tcpdf

Copyright

2016 - 2023

Author

Markus Mächler, Esteban Gehring

Email

markus.maechler@bithost.ch, esteban.gehring@bithost.ch

License

This document is published under the Open Content License available from http://www.opencontent.org/opl.shtml

Rendered

Fri, 23 May 2025 10:30:04 +0000

The content of this document is related to TYPO3, a GNU/GPL CMS/Framework available from www.typo3.org.

Table of Contents

Introduction

What does it do?

This is a TYPO3 CMS extension that provides various Fluid ViewHelpers to generate PDF documents. Using the ViewHelpers from this extension you can make any Fluid template into a PDF document. The extension pdfviewhelpers is using TCPDF and FPDI for the PDF generation.

Key features

  • ViewHelpers to render text and lists
  • ViewHelper to render images (supporting FAL and image processing)
  • ViewHelpers to repeatedly render header and footer
  • ViewHelper to render HTML / rich-text content
  • ViewHelper to avoid page breaks inside
  • ViewHelpers to create a multi column layout
  • ViewHelpers to create a table of content
  • Load existing PDF documents as template
  • Define and apply different text types easily
  • Fully customizable by writing your own ViewHelpers
  • Supports batch creation of PDFs
  • Supported output destinations: string, inline, download and file
  • Usable both in frontend and backend
  • Rich inheritance based TypoScript settings
  • Rich API documentation with lots of examples

Installation

Install the extension using the extension manager and include the static TypoScript template of the extension.

TypoScript Reference

Settings inheritance

To avoid redundancy there is an inheritance structure within the settings. There are basically three levels top down:

  1. plugin.tx_pdfviewhelpers.settings.document|page|generalText: The top level are global settings for document, page and generalText (all textual output).
  2. plugin.tx_pdfviewhelpers.settings.headline|text|list: Headline, text and list inherit settings from generalText. All the settings from generalText may be overwritten here with specific settings.
  3. Fluid ViewHelper attributes: The bottom level are Fluid ViewHelper attributes. All TypoScript settings may be overwritten using Fluid ViewHelper attributes with the same name. e.g:
{namespace pdf=Bithost\Pdfviewhelpers\ViewHelpers}

<pdf:document outputDestination="I" title="Bithost Example">
	<pdf:page autoPageBreak="1">
		<pdf:headline color="#333">Different color</pdf:headline>
	</pdf:page>
</pdf:document>
Copied!

Properties in plugin.tx_pdfviewhelpers.settings

Property Data type Default
config.class_ string Bithost\Pdfviewhelpers\Model\BasePDF
config.disableCache_ boolean 1
config.exitAfterPdfContentOutput_ boolean 0
config.jpgQuality_ integer 100
config.sRGBMode_ boolean 0
config.allowedImageTypes_ Array See static TypoScript template
config.fonts.subset_ boolean 1
config.fonts.addTTFFont_ Array See static TypoScript template
config.fonts.outputPath_ string typo3temp/pdfviewhelpers/fonts/
document.title_ string  
document.subject_ string  
document.author_ string  
document.keywords_ string  
document.creator_ string TYPO3 EXT:pdfviewhelpers
document.outputDestination_ string inline
document.outputPath_ string document.pdf
document.sourceFile_ string  
document.unit_ string mm
document.unicode_ boolean 1
document.encoding_ string UTF-8
document.pdfa_ boolean 0
document.pdfua_ boolean 0
document.language_ string ger
document.hyphenFile_ string hyph-de-ch-1901.tex
page.autoPageBreak_ boolean 0
page.margin_ Array {top: 15, right: 15, bottom: 15, left: 15}
page.importPage_ integer  
page.importPageOnAutomaticPageBreak_ boolean 1
page.orientation_ string portrait
page.format_ string A4
page.keepMargins_ boolean 0
page.tableOfContentPage_ boolean 0
header.posY_ integer 5
footer.posY_ integer -10
avoidPageBreakInside.breakIfImpossibleToAvoid_ boolean 0
generalText.trim_ boolean 1
generalText.removeDoubleWhitespace_ boolean 1
generalText.color_ string #000
generalText.fontFamily_ string helvetica
generalText.fontSize_ integer 11
generalText.fontStyle_ string regular
generalText.lineHeight_ t3tsref:data-type-float 1.25
generalText.characterSpacing_ t3tsref:data-type-float 0
generalText.padding_ Array {top: 0, right: 0, bottom: 0, left: 0}
generalText.alignment_ string left
generalText.paragraphSpacing_ integer 2
generalText.paragraphLineFeed_ boolean 0
generalText.autoHyphenation_ boolean 0
text.trim boolean See generalText
text.removeDoubleWhitespace boolean See generalText
text.color. string See generalText
text.fontFamily string See generalText
text.fontSize integer See generalText
text.fontStyle string See generalText
text.lineHeight t3tsref:data-type-float See generalText
text.characterSpacing t3tsref:data-type-float See generalText
text.padding Array See generalText
text.alignment string See generalText
text.paragraphSpacing integer See generalText
text.paragraphLineFeed boolean See generalText
text.autoHyphenation boolean See generalText
headline.trim boolean See generalText
headline.removeDoubleWhitespace boolean See generalText
headline.color string See generalText
headline.fontFamily string See generalText
headline.fontSize integer See generalText
headline.fontStyle string See generalText
headline.lineHeight t3tsref:data-type-float See generalText
headline.characterSpacing t3tsref:data-type-float See generalText
headline.padding Array {top: 6, bottom: 3}
headline.alignment string See generalText
headline.paragraphSpacing integer See generalText
headline.paragraphLineFeed boolean See generalText
headline.autoHyphenation boolean See generalText
headline.addToTableOfContent boolean 0
headline.tableOfContentLevel integer 0
list.trim boolean See generalText
list.removeDoubleWhitespace boolean See generalText
list.color string See generalText
list.fontFamily string See generalText
list.fontSize integer See generalText
list.fontStyle string See generalText
list.lineHeight t3tsref:data-type-float See generalText
list.characterSpacing t3tsref:data-type-float See generalText
list.paragraphLineFeed boolean See generalText
list.padding Array {bottom: 2, left: 1.5}
list.alignment string left
list.bulletColor_ string #000
list.bulletImageSrc_ string  
list.bulletSize_ t3tsref:data-type-float 1.5
list.autoHyphenation boolean See generalText
image.alignment_ string left
image.fitOnPage_ boolean 1
image.padding_ Array {bottom: 2}
image.processingInstructions_ Array {}
html.autoHyphenation boolean See generalText
html.styleSheet_ string  
html.listIndentWidth_ t3tsref:data-type-float  
html.padding_ Array {top: 0, right: 0, bottom: 2, left: 0}
graphics.line.padding_ Array {top: 4, right: 0, bottom: 5, left: 0}
graphics.line.style_ Array {width: 0.25, color: #000}
tableOfContent.page_ integer 1
tableOfContent.numbersFont_ string  
tableOfContent.filter_ string .
tableOfContent.name_ string  
tableOfContent.htmlMode_ boolean 0
tableOfContent.fontFamily_ string  
tableOfContent.fontSize_ t3tsref:data-type-float  
tableOfContent.lineHeight_ t3tsref:data-type-float  
tableOfContent.characterSpacing_ t3tsref:data-type-float  
tableOfContent.padding_ Array {bottom: 2}
htmlBookmarkTemplate.level_ integer 0
htmlBookmarkTemplate.sanitizeWhitespace_ boolean 1
bookmark.level_ integer 0
bookmark.fontStyle_ string  
bookmark.color_ string  

Property details

config.class

plugin.tx_pdfviewhelpers.settings.config.class = string

Decides which PHP class should be used as TCPDF object. You can easily provide your own class in order to render custom header and footers or to customize TCPDF in any way. Your provided class must inherit from Bithost\Pdfviewhelpers\Model\BasePDF.

config.disableCache

plugin.tx_pdfviewhelpers.settings.config.disableCache = boolean

Decides whether the TYPO3 frontend cache will be disabled or not.

config.exitAfterPdfContentOutput

plugin.tx_pdfviewhelpers.settings.config.exitAfterPdfContentOutput = boolean

Decides whether the PHP method exit is called after the PDF content has been sent to the browser. This might solve issues when additional content is echoed and appended to the PDF document. However it might also lead to other unexpected behaviour so be careful.

config.jpgQuality

plugin.tx_pdfviewhelpers.settings.config.jpgQuality = integer

JpgQuality being used, values from 0 - 100.

config.sRGBMode

plugin.tx_pdfviewhelpers.settings.config.sRGBMode = boolean

Enable sRGBMode, see TCPDF documentation for further information.

config.allowedImageTypes

plugin.tx_pdfviewhelpers.settings.config.allowedImageTypes = Array

Mapping of TCPDF image functions to their corresponding image file extensions.

config.fonts.subset

plugin.tx_pdfviewhelpers.settings.config.fonts.subset = boolean

Decides whether to subset the used fonts or not. When this is set to true it is not possible to edit the generated PDF if the font is not present in the users system, but the file size gets smaller.

config.fonts.addTTFFont

plugin.tx_pdfviewhelpers.settings.config.fonts.addTTFFont = Array

Possibility to add custom fonts, please have a look at the dedicated chapter Custom Fonts.

config.fonts.outputPath

plugin.tx_pdfviewhelpers.settings.config.fonts.outputPath = string

Path to directory where font files of custom fonts should be stored. This folder can safely be deleted and will automatically be re/created if it does not exist.

document.title

plugin.tx_pdfviewhelpers.settings.document.title = string

The title of the generated PDF document.

document.subject

plugin.tx_pdfviewhelpers.settings.document.subject = string

The subject of the generated PDF document.

document.author

plugin.tx_pdfviewhelpers.settings.document.author = string

The author of the generated PDF document.

document.keywords

plugin.tx_pdfviewhelpers.settings.document.keywords = string

A comma separated list of keywords for the generated PDF document.

document.creator

plugin.tx_pdfviewhelpers.settings.document.creator = string

The creator of the generated PDF document.

document.outputDestination

plugin.tx_pdfviewhelpers.settings.document.outputDestination = string

The TCPDF output destination for the PDF. Possible values are:

outputDestination Description
I / inline Sending the PDF inline to the browser.
D / download Sending the PDF as immediate file download.
F / file Saving the PDF to the specified outputPath.
FI / file-inline Saving the PDF to the specified outputPath and sending it inline to the browser.
FD / file-downloa Saving the PDF to the specified outputPath and sending it as immediate file download.
E / email Return the PDF as base64 mime multi-part email attachment (RFC 2045).
S / string Return the PDF as string.

document.outputPath

plugin.tx_pdfviewhelpers.settings.document.outputPath = string

The TCPDF output path of the document. If you are saving the file to filesystem this is a relative path from the webroot directory e.g. fileadmin/pdfviewhelpers/projectXY.pdf. If you are sending it inline or as file download it is simply the name of the document e.g. projectXY.pdf.

document.sourceFile

plugin.tx_pdfviewhelpers.settings.document.sourceFile = string

The sourceFile is a the path to a PDF document you want to use as a template (see also page.importPage).

document.unit

plugin.tx_pdfviewhelpers.settings.document.unit = string

The measurement unit used. Possible values are pt, mm, cm and in.

document.unicode

plugin.tx_pdfviewhelpers.settings.document.unicode = boolean

Determines whether the input text is unicode or not.

document.encoding

plugin.tx_pdfviewhelpers.settings.document.encoding = string

Charset encoding (used only when converting back html entities).

document.pdfa

plugin.tx_pdfviewhelpers.settings.document.pdfa = boolean

Sets the document to PDF/A mode if true.

document.pdfua

plugin.tx_pdfviewhelpers.settings.document.pdfua = boolean

Enables experimental support for PDF/UA. Please note that this feature is very much incomplete, feel free to contribute any improvements on this!

document.language

plugin.tx_pdfviewhelpers.settings.document.language = string

Decides which language settings are used from TCPDF. All possible language codes can be found in Resources/Private/tcpdf/examples/lang/.

document.hyphenFile

plugin.tx_pdfviewhelpers.settings.document.hyphenFile = string

The name of the hyphen file used for the automatic hyphenation. This needs to be set according to the language of your document. All possible values can be found in the directory pdfviewhelpers/Resources/Private/Hyphenation/.

Example values are: hyph-de-1996.tex, hyph-en-gb.tex, hyph-nl.tex, hyph-fr.tex

page.autoPageBreak

plugin.tx_pdfviewhelpers.settings.page.autoPageBreak = boolean

Decides whether TCPDF uses auto page break or not. You can always add a new page by adding a new <pdf:page> tag to your template.

page.margin

plugin.tx_pdfviewhelpers.settings.page.margin = Array

An array of the margin for each page. The default unit is millimeters.

page.importPage

plugin.tx_pdfviewhelpers.settings.page.importPage = integer

Specifies which page should be used as template for the current page. Must be used together with document.sourceFile.

page.importPageOnAutomaticPageBreak

plugin.tx_pdfviewhelpers.settings.page.importPageOnAutomaticPageBreak = boolean

Determines whether a PDF template that is used on a page is also rendered when an automatic page break occurs.

page.orientation

plugin.tx_pdfviewhelpers.settings.page.orientation = string

Defines the orientation of the current page and the following pages. Possible values are P / portrait and L / landscape.

page.format

plugin.tx_pdfviewhelpers.settings.page.format = string

Defines the format of the current page. Possible values are e.g. A0 - A12, to see all possible values you have to check \TCPDF_STATIC::$page_formats. You can also provide numeric values as fluid array e.g. {0:210,1:75} to set unusual page sizes.

page.keepMargins

plugin.tx_pdfviewhelpers.settings.page.keepMargins = string

If true overwrites the default page margins with the current margins.

page.tableOfContentPage

plugin.tx_pdfviewhelpers.settings.page.tableOfContentPage = string

If true the page will be rendered as a table of content page, e.g. it can be moved to the front.

header.posY

plugin.tx_pdfviewhelpers.settings.header.posY = integer

Defines the header position relative to the top of the page.

avoidPageBreakInside.breakIfImpossibleToAvoid

plugin.tx_pdfviewhelpers.settings.avoidPageBreakInside.breakIfImpossibleToAvoid = boolean

If set to true this ViewHelper inserts a page break even if the content does not fit on one page, meaning a page break is unavoidable.

generalText.trim

plugin.tx_pdfviewhelpers.settings.generalText.trim = boolean

If set to true leading and trailing spaces or tabs are trimmed.

generalText.removeDoubleWhitespace

plugin.tx_pdfviewhelpers.settings.generalText.removeDoubleWhitespace = boolean

If set to true double spaces within text elements are removed.

generalText.color

plugin.tx_pdfviewhelpers.settings.generalText.color = string

The text color as hex value, possible syntax are: #000 or #000000

generalText.fontFamily

plugin.tx_pdfviewhelpers.settings.generalText.fontFamily = string

The font family being used. A list of available fonts and a configuration to add your own fonts is available in the chapter custom fonts.

generalText.fontSize

plugin.tx_pdfviewhelpers.settings.generalText.fontSize = integer

The font size being used.

generalText.fontStyle

plugin.tx_pdfviewhelpers.settings.generalText.fontStyle = string

The font style being used. Possible values are: R / regular, B / bold, I / italic, U / underline

generalText.lineHeight

plugin.tx_pdfviewhelpers.settings.generalText.lineHeight = t3tsref:data-type-float

Sets the line height with respect to the font size.

generalText.characterSpacing

plugin.tx_pdfviewhelpers.settings.generalText.characterSpacing = t3tsref:data-type-float

Sets the spacing between individual characters

generalText.padding

plugin.tx_pdfviewhelpers.settings.generalText.padding = Array

An array of the padding for each text element. The default unit is millimeters.

generalText.alignment

plugin.tx_pdfviewhelpers.settings.generalText.alignment = string

Possible values are: L / left, C / center, R / right, J / justify

generalText.paragraphSpacing

plugin.tx_pdfviewhelpers.settings.generalText.paragraphSpacing = integer

Defines the spacing of paragraphs separated by new lines.

generalText.paragraphLineFeed

plugin.tx_pdfviewhelpers.settings.generalText.paragraphLineFeed = boolean

Add new lines char after each paragraph (in justified text keeps left align the last line of each paragraph).

generalText.autoHyphenation

plugin.tx_pdfviewhelpers.settings.generalText.autoHyphenation = boolean

A boolean value indicating whether to use TCPDF's automatic hyphenation or not. You can also add soft hyphens yourself to your text with "&shy;". If you use automatic hyphenation please make sure that you configure "config.hyphenFile" to match your language.

headline.addToTableOfContent

plugin.tx_pdfviewhelpers.settings.generalText.addToTableOfContent = boolean

If true the headline will be added to the table of content.

headline.tableOfContentLevel

plugin.tx_pdfviewhelpers.settings.generalText.tableOfContentLevel = integer

Indicating the level of the headline in the table of content. Starting from 0 as top level, 1 for second, 2 for third level and so on.

list.bulletColor

plugin.tx_pdfviewhelpers.settings.list.bulletColor = string

The color of the bullet used as hex value, possible syntax are: #000 or #000000

list.bulletImageSrc

plugin.tx_pdfviewhelpers.settings.list.bulletImageSrc = string

The path to an image that should be used as bullet.

list.bulletSize

plugin.tx_pdfviewhelpers.settings.list.bulletSize = t3tsref:data-type-float

The size of the bullet as floating point value.

image.alignment

plugin.tx_pdfviewhelpers.settings.image.alignment = string

Possible values are: L / left, C / center, R / right

image.fitOnPage

plugin.tx_pdfviewhelpers.settings.image.fitOnPage = boolean

If true the image will automatically be rescaled to fit on page.

image.padding

plugin.tx_pdfviewhelpers.settings.image.padding = Array

The padding around the image.

image.processingInstructions

plugin.tx_pdfviewhelpers.settings.image.processingInstructions = Array

An array of processing instructions that is passed to the method ImageService->applyProcessingInstructions. A possible configuration looks like this:

processingInstructions {
	width =
	height =
	maxHeight =
	minWidth =
	maxWidth = 200
	minHeight =
	crop {
		custom_crop {
			cropArea {
				width = 0.5
				height = 0.5
				x = 0
				y = 0
			}
		}
	}
	cropVariant = custom_crop
}

Copied!

html.styleSheet

plugin.tx_pdfviewhelpers.settings.html.styleSheet = string

The path to a style sheet being used in the HtmlViewHelper. The can be provided relative to the webroot directory, e.g. "fileadmin/pdf_style.css".

html.padding

plugin.tx_pdfviewhelpers.settings.html.padding = Array

The padding around the html element.

graphics.line.padding

plugin.tx_pdfviewhelpers.settings.graphics.line.padding = Array

Defines the padding around a line. The default unit is millimeters.

graphics.line.style

plugin.tx_pdfviewhelpers.settings.graphics.line.style = Array

An array defining line styles, please see the https://tcpdf.org/examples/example_012/ for all possible values.

tableOfContent.page

plugin.tx_pdfviewhelpers.settings.tableOfContent.page = integer

Indicates at what place in the document the table of content will be rendered.

tableOfContent.numbersFont

plugin.tx_pdfviewhelpers.settings.tableOfContent.numbersFont = string

The font used to render the numbers. Note that a monospaced font must be used in order to guarantee correct alignment.

tableOfContent.filter

plugin.tx_pdfviewhelpers.settings.tableOfContent.filter = string

The filter used to fill up the space between the entry title and the page number.

tableOfContent.name

plugin.tx_pdfviewhelpers.settings.tableOfContent.name = string

The name used for the table of content bookmark.

tableOfContent.htmlMode

plugin.tx_pdfviewhelpers.settings.tableOfContent.htmlMode = boolean

If true the table of content is rendered in HTML mode.

tableOfContent.fontFamily

plugin.tx_pdfviewhelpers.settings.tableOfContent.fontFamily = string

The fontFamily for the entries. Also see See generalText.

tableOfContent.fontSize

plugin.tx_pdfviewhelpers.settings.tableOfContent.fontSize = t3tsref:data-type-float

The fontSize of the top most level. Also see See generalText.

tableOfContent.lineHeight

plugin.tx_pdfviewhelpers.settings.tableOfContent.lineHeight = t3tsref:data-type-float

The lineHeight used for the table content entries. Also see See generalText.

tableOfContent.characterSpacing

plugin.tx_pdfviewhelpers.settings.tableOfContent.characterSpacing = t3tsref:data-type-float

The characterSpacing used for the table content entries. Also see See generalText.

tableOfContent.padding

plugin.tx_pdfviewhelpers.settings.tableOfContent.padding = Array

The cell padding used for the table content entries.

htmlBookmarkTemplate.level

plugin.tx_pdfviewhelpers.settings.htmlBookmarkTemplate.level = integer

The bookmark entry level to which the HTML template should apply.

htmlBookmarkTemplate.sanitizeWhitespace

plugin.tx_pdfviewhelpers.settings.htmlBookmarkTemplate.sanitizeWhitespace = boolean

If true the input will be trimmed and whitespaces between HTML tags will be removed.

bookmark.level

plugin.tx_pdfviewhelpers.settings.bookmark.level = boolean

The table of content level for the bookmark.

bookmark.fontStyle

plugin.tx_pdfviewhelpers.settings.bookmark.fontStyle = boolean

The fontStyle this individual bookmark. Also see See generalText.

bookmark.color

plugin.tx_pdfviewhelpers.settings.bookmark.fontStyle = boolean

The fontStyle this individual bookmark. Also see See generalText.

Text Types

It is possible to define multiple default text styles and then apply them to a ViewHelper using the type attribute. This is for instance useful if you have different types of headlines. It is possible to define types for the TextViewHelper, HeadlineViewHelper and ListViewHelper. In addition you can define types in the generalText section, these types are available for all ViewHelpers mentioned.

Text types take part in the settings inheritance, with the following priority (higher priority overwrites lower priority):

  1. settings.generalText
  2. settings.text | settings.headline | settings.list
  3. settings.text.types | settings.headline.types | settings.list.types | settings.generalText.types
  4. ViewHelper arguments

TypoScript

plugin.tx_pdfviewhelpers.settings {
	headline {
		types {
			h1 {
				fontSize = 24
				padding {
					top = 6
					bottom = 3
				}
			}
			h2 {
				fontsize = 18
				padding {
					top = 4
					bottom = 2
				}
			}
			h3 {
				fontSize = 11
				fontStyle = bold
				padding {
					top = 2
					bottom = 1
				}
			}
		}
	}
}

Copied!

Fluid

<pdf:headline type="h1">Rendered as h1</pdf:headline>
<pdf:headline type="h2">Rendered as h2</pdf:headline>
<pdf:headline type="h3">Rendered as h3</pdf:headline>
Copied!

Extend Existing PDFs

It is possible to use existing PDFs as template and extend the PDF where needed. You can either load the template PDF within the TypoScript settings or within the Fluid template itself.

TypoScript

plugin.tx_pdfviewhelpers.settings {
	config {
		class = Bithost\Pdfviewhelpers\Model\BasePDF
	}
	document {
		sourceFile = EXT:pdfviewhelpers/Resources/Public/Examples/ExtendExistingPDFs/pdf_template.pdf
	}
	page {
		importPage = 1
		importPageOnAutomaticPageBreak = 1
	}
}

Copied!

Fluid Template

{namespace pdf=Bithost\Pdfviewhelpers\ViewHelpers}

<pdf:document sourceFile="EXT:pdfviewhelpers/Resources/Public/Examples/ExtendExistingPDFs/pdf_template.pdf">
	<pdf:page importPage="1" margin="{top: 80, right: 20, bottom: 40, left: 20}" importPageOnAutomaticPageBreak="0">
		<pdf:text>Your own text is shown here.</pdf:text>
	</pdf:page>
</pdf:document>
Copied!

Custom Fonts

Adding custom fonts is as easy as providing the path to the TTF file within your TypoScript settings. The name of the font is automatically generated by TCPDF using the font file name. Only the characters a-z, 0-9 and _ are allowed and words like bold, oblique, italic or regular are replaced by b, o, i or [empty].

Example: ROBOTObold.ttf becomes robotob

Please note that the TypoScript key you use is not the font name, the font name is generated only based on the font file name!

TypoScript

plugin.tx_pdfviewhelpers.settings.config.fonts {
	addTTFFont {
		roboto {
			path = EXT:pdfviewhelpers/Resources/Public/Examples/FullFeatureShowCase/Roboto.ttf

			# Font type. Leave empty for autodetect mode. Valid values are: TrueTypeUnicode, TrueType, Type1, CID0JP = CID-0 Japanese, CID0KR = CID-0 Korean, CID0CS = CID-0 Chinese Simplified, CID0CT = CID-0 Chinese Traditional.
			# type = TrueTypeUnicode

			# Name of the encoding table to use. Leave empty for default mode. Omit this parameter for TrueType Unicode and symbolic fonts like Symbol or ZapfDingBats.
			# enc =

			# Unsigned 32-bit integer containing flags specifying various characteristics of the font (PDF32000:2008 - 9.8.2 Font Descriptor Flags): +1 for fixed font; +4 for symbol or +32 for non-symbol; +64 for italic. Fixed and Italic mode are generally autodetected so you have to set it to 32 = non-symbolic font (default) or 4 = symbolic font.
			# flags =
		}
		opensans {
			path = EXT:pdfviewhelpers/Resources/Public/Examples/FullFeatureShowCase/OpenSans.ttf
		}
	}
}

Copied!

TCPDF fonts

TCPDF comes already with the following fonts installed: courier, helvetica, symbol, times and zapfdingbats

Limitations

TCPDF does not support OpenType fonts with CFF data. If your font can not be added, please try to convert it to TTF, there are a couple of free online converters available.

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

<?php

namespace Vendor\YourExtension\ViewHelpers;

/***
 *
 * This file is part of the "PDF ViewHelpers" Extension for TYPO3 CMS.
 *
 *  (c) 2016 Markus Mächler <markus.maechler@bithost.ch>, Bithost GmbH
 *           Esteban Gehring <esteban.gehring@bithost.ch>, 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 <markus.maechler@bithost.ch>, Esteban Gehring <esteban.gehring@bithost.ch>
 */
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');
    }
}
Copied!

Fluid

{namespace pdf=Bithost\Pdfviewhelpers\ViewHelpers}
{namespace you=Vendor\YourExtension\ViewHelpers}

<pdf:document>
	<pdf:page>
		<you:barcode title="Some Title" code="CODE 39" type="C39" />
	</pdf:page>
</pdf:document>

Copied!

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
	}
}
Copied!

PHP

<?php

namespace Vendor\YourExtension\Model;

/***
 *
 * This file is part of the "PDF ViewHelpers" Extension for TYPO3 CMS.
 *
 *  (c) 2016 Markus Mächler <markus.maechler@bithost.ch>, Bithost GmbH
 *           Esteban Gehring <esteban.gehring@bithost.ch>, 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 <markus.maechler@bithost.ch>, Esteban Gehring <esteban.gehring@bithost.ch>
 */
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');
    }
}
Copied!

Caching

The extension pdfviewhelpers does not provide any caching mechanism for the generated PDF documents. In fact caching is disabled by default because it makes not much sense to save a PDF document to the TYPO3 frontend cache. Since generating PDF documents is quite time consuming you should implement your own caching strategy by saving the generated PDF files to the filesystem and only generate them when necessary.

It is not possible to cache the Fluid template parsing when using the MultiColumnViewHelper because it implements the ChildNodeAccessInterface. This may lead to a significant loss in performance for that view.

EXT:news integration

The extension pdfviewhelpers ships with a PDF template for EXT:news. You can use the default template provided or customize it in any way.

Enable default template

To enable the default template you have to include the static TypoScript template pdfviewhelpers - EXT:news. All the TypoScript settings that are needed are limited to the special page type 28032013. In order to link to the PDF view you have to include this page type in the link generation:

<n:link newsItem="{newsItem}" settings="{settings}" title="{newsItem.title}" configuration="{additionalParams: '&type=28032013'}">
	Download as PDF
</n:link>
Copied!

Customising the PDF

Most of the typography aspects can be changed solely through TypoScript configuration by changing the existing text types (see also text types). Please make sure that all your configuration is limited to the page type 28032013.

[request && traverse(request.getQueryParams(), 'type') == 28032013]
	plugin.tx_pdfviewhelpers.settings {
		text {
			types {
				teaser {
					fontStyle = regular
					fontSize = 16
				}
				footer {
					alignment = center
				}
			}
		}
		headline {
			types {
				title {
					color = #ff642c
				}
			}
		}
	}

	module.tx_pdfviewhelpers < plugin.tx_pdfviewhelpers
[global]
Copied!

If you need to change the layout or extend the header and footer content, you can provide your own Fluid template that is located in EXT:yourext/Resources/Private/Templates/Extensions/News/Templates/News/Detail.html:

[request && traverse(request.getQueryParams(), 'type') == 28032013]
	plugin.tx_news {
		view {
			templateRootPaths {
				5 = EXT:yourext/Resources/Private/Templates/Extensions/News/Templates/
			}
		}
	}
[global]
Copied!

ViewHelpers

For detailed information about the ViewHelper attributes please refer to the Configuration Reference.

DocumentViewHelper

This ViewHelper must be the first to be used in your template and wrap all the other ViewHelpers. It is responsible for generating the document.

Basic Usage

<pdf:document>
[..]

</pdf:document>

Advanced Usage

<pdf:document
title="Bithost Example" subject="Welcome message" author="Bithost GmbH" keywords="example, test" outputDestination="inline" outputPath="example.pdf" sourceFile="EXT:pdfviewhelpers/Resources/Public/Examples/ExtendExistingPDFs/pdf_template.pdf" unit="cm" unicode="1" encoding="UTF-8" pdfa="1"> [..]

</pdf:document>

PageViewHelper

This ViewHelper must be placed right within a document ViewHelper. It can be used to manually add new pages.

Basic Usage

<pdf:document>
<pdf:page>
<pdf:text>Page 1</pdf:text>

</pdf:page> <pdf:page> <pdf:text>Page 2</pdf:text> </pdf:page>

</pdf:document>

Advanced Usage

<pdf:document>
<pdf:page autoPageBreak="1" orientation="landscape" format="A5">
<pdf:text>Page 1</pdf:text>

</pdf:page> <pdf:page autoPageBreak="0" orientation="portrait" format="A3" margin="{top: 40}"> <pdf:text>Page 2</pdf:text> </pdf:page> <pdf:page tableOfContentPage="1"></pdf:page>

</pdf:document>

PageBreakViewHelper

Adds a page break within a single page. Can be used for conditional page breaks for instance.

<pdf:page>
	Page 1
	<pdf:pageBreak />
	Page 2

	Conditional page break
	<f:if condition="{someCondition}">
		<pdf:pageBreak />
	</f:if>
</pdf:page>
Copied!

HeaderViewHelper and FooterViewHelper

These ViewHelpers can be used to set header and footer for pages. Thereby they are always applied to one of the following scopes:

  • document: The header and footer are applied to all the pages.
  • thisPage: The header and footer are only applied to the first page they are set on.
  • thisPageIncludingPageBreaks The header and footer are only applied to the page they are set on including sub pages triggered by an auto page break or the PageBreakViewHelper.

The scope is implicitly set depending on where you place the ViewHelpers. ViewHelpers that are descendants of the DocumentViewHelper have as default scope document applied. ViewHelpers that are descendants of the PageViewHelper have as default scope thisPageIncludingPageBreaks applied. It is also possible to set the scope explicitly using the scope ViewHelper attribute.

ViewHelpers that are defined within a PageViewHelper may overwrite ViewHelpers that are defined on document level. Please see the examples section for an extended example of the header and footer usage.

AvoidPageBreakInsideViewHelper

This ViewHelper may wrap any composition of other ViewHelpers. It tries its best to avoid a page break within its children elements. Note that this ViewHelper needs to render its children two times to determine whether a page break is needed or not. This has a negative impact on the performance as well as might create other undesired side effects.

<pdf:document>
	<pdf:page>
		<pdf:headline>Welcome to the extension pdfviewhelpers</pdf:headline>
		<pdf:text>Lorem ipsum.</pdf:text>

		<pdf:avoidPageBreakInside>
			<pdf:headline>Some more information</pdf:headline>
			<pdf:multiColumn>
				<pdf:column>
					<pdf:text>Lorem ipsum.</pdf:text>
				</pdf:column>
				<pdf:column>
					<pdf:image src="EXT:pdfviewhelpers/Resources/Public/Examples/BasicUsage/Bithost.jpg"/>
					<pdf:text padding="{top: 1}" color="#8C8C8C">Esteban Gehring, Markus Mächler</pdf:text>
				</pdf:column>
			</pdf:multiColumn>
		</pdf:avoidPageBreakInside>
	</pdf:page>
</pdf:document>
Copied!

MultiColumnViewHelper / ColumnViewHelper

These ViewHelpers have to be used together in order to generate a multi column layout. By default all columns are of equal width. It is however possible to specify the width of a column with an absolute or percentage value. In addition it possible to set a padding value for each column.

Important: The parsing of the Fluid template can not be cached when these ViewHelpers are used. This can lead to a significant loss in performance.

Basic Usage

<pdf:multiColumn>
<pdf:column>
<pdf:text>Column 1</pdf:text>

</pdf:column> <pdf:column> <pdf:text>Column 2</pdf:text> </pdf:column> <pdf:column> <pdf:text>Column 3</pdf:text> </pdf:column>

</pdf:multiColumn>

Advanced Usage

<pdf:multiColumn>
<pdf:column width="60%" padding="{right: 2}">
<pdf:text>Column 1</pdf:text>

</pdf:column> <pdf:column width="20%" padding="{right: 2}"> <pdf:text>Column 2</pdf:text> </pdf:column> <pdf:column width="20%"> <pdf:text>Column 3</pdf:text> </pdf:column>

</pdf:multiColumn>

<pdf:multiColumn>
<pdf:column width="100">
<pdf:text>Column 1</pdf:text>

</pdf:column> <pdf:column width="45"> <pdf:text>Column 2</pdf:text> </pdf:column> <pdf:column width="45"> <pdf:text>Column 3</pdf:text> </pdf:column>

</pdf:multiColumn>

TextViewHelper

Rendering text using the settings for text. It is possible to easily define different default styles and apply them using the type attribute, see chapter Text Types.

Basic Usage

<pdf:text>Title</pdf:text>
<pdf:text text="Alternative syntax"/>

Advanced Usage

<pdf:text
trim="0" removeDoubleWhitespace="1" color="#333" fontFamily="arial" fontSize="22" fontStyle="bold" lineHeight="1.5" characterSpacing="0.2" alignment="right" paragraphSpacing="0" paragraphLineFeed="1" autoHyphenation="1" padding="{top: 1, right: 0, bottom: 0, left: 0}" width="80%" >Title</pdf:text>

HeadlineViewHelper

Rendering text using the settings for headlines. It is possible to easily define different default styles and apply them using the type attribute, see chapter Text Types. Text rendered with a HeadlineViewHelper can be added to the table of content automatically by setting plugin.tx_pdfviewhelpers.settings.headline.addToTableOfContent = 1.

Basic Usage

<pdf:headline>Title</pdf:headline>
<pdf:headline text="Alternative syntax"/>

Advanced Usage

<pdf:headline
trim="0" removeDoubleWhitespace="1" color="#333" fontFamily="arial" fontSize="22" fontStyle="bold" lineHeight="1.5" characterSpacing="0.2" alignment="right" paragraphSpacing="0" paragraphLineFeed="1" autoHyphenation="1" padding="{top: 1, right: 0, bottom: 0, left: 0}" width="100" addToTableOfContent="0" tableOfContentLevel="1" >Title</pdf:headline>

ListViewHelper

Rendering a list given as a one dimensional array. It is possible to easily define different default styles and apply them using the type attribute, see chapter Text Types.

Basic Usage

<pdf:list listElements="{0: 'Full Stack Application Development', 1: 'Modernizing, Refactoring and Migrating Applications', 2: 'Active Collaboration in an existing Team', 3: 'Consulting and Support for IT Projects'}"/>
<pdf:list listElements="{someArrayProperty}"/>

Advanced Usage

<pdf:list

trim="1" removeDoubleWhitespace="1" color="#999999" fontFamily="arial" fontSize="14" fontStyle="bold" lineHeight="1.5" characterSpacing="0.2" paragraphLineFeed="1" alignment="center" autoHyphenation="1" padding="{top:1, right:0, bottom:0, left:0}"

bulletColor="#333" bulletImageSrc="EXT:pdfviewhelpers/some/path/image.png" bulletSize="2.5"

listElements="{0: 'Full Stack Application Development', 1: 'Modernizing, Refactoring and Migrating Applications', 2: 'Active Collaboration in an existing Team', 3: 'Consulting and Support for IT Projects'}" />

HtmlViewHelper

Rendering any html content using TCPDF's method writeHTML. The default text settings are those from generalText. It is possible to include a css style tag and also inline styles. This ViewHelper is especially useful for rendering Rich Text.

Please note that the use of CSS within a style tag can lead to parsing issues with Fluid, use an external style sheet in that case.

Basic Usage

<pdf:html>
<h1>Some html headline</h1> <p>Lorem ipsum</p>

</pdf:html>

Advanced Usage

<pdf:html styleSheet="fileadmin/template/pdf_styles.css" autoHyphenation="1" padding="{bottom: 5}" listIndentWidth="0">
<style>
h1 {
color: #ff642c;

}

</style>

<h1>Some html headline</h1> <p style="color: #3a718a;">Lorem ipsum</p>

{someAdditionalRichText}

</pdf:html>

ImageViewHelper

This ViewHelper renders an image given as src. As src argument you may provide a valid TYPO3 path or an object implementing TYPO3 FAL FileInterface (e.g. File or FileReference).

<pdf:image src="EXT:pdfviewhelpers/Resources/Public/Example/Bithost.jpg" width="200" />
<pdf:image src="{file}" width="50%" alignment="center" link="https://www.bithost.ch" />
<pdf:image src="{fileReference}" width="100" alignment="right" padding="{right: 10}" fitOnPage="0" />
Copied!

The Image ViewHelper supports image processing using the processingInstructions attribute. The attribute value is directly passed to ImageService->applyProcessingInstructions, thus it supports all configurations supported by this method. There is no need to set the crop or cropVariant in the processingInstructions in case you use the default crop of a file object.

<pdf:image src="{file}" processingInstructions="{maxWidth: '600'}" />
<pdf:image src="{file}" processingInstructions="{width: '200c'}" width="200" />
<pdf:image src="{file}" processingInstructions="{cropVariant: 'pdf_crop'}" />
<pdf:image src="{file}" processingInstructions="{cropVariant: 'pdf_crop', crop: cropArrayOrString}" />
Copied!

LineBreakViewHelper

Adds a line break of given height, this can be used to add margin between elements.

<pdf:lineBreak height="10" />
Copied!

Graphics LineViewHelper

This ViewHelper allows to render a simple line. By default it renders a horizontal line matching the current page width. It is however also possible to specify start and end point of the line explicitly. Please see https://tcpdf.org/examples/example_012/ to find out what values can be used on the style attribute.

Basic Usage

<pdf:graphics.line />

Advanced Usage

<pdf:graphics.line
padding="{top: 1, right: 10, bottom: 1, left: 10}" style="{color: '#8C8C8C', width: 0.5}" />

GetPageNumberAliasViewHelper / GetTotalNumberOfPagesAliasViewHelper

These ViewHelpers return alias strings to the current page number as well as the total number of pages. Please note that they do not return an integer value, but a string that is replaced by the correct number at the end of the PDF generation. This may lead to alignment errors when trying to align text including these ViewHelpers right or centered.

{pdf:getPageNumberAlias()}
{pdf:getTotalNumberOfPagesAlias()}
Copied!

GetPosXViewHelper / GetPosYViewHelper

These ViewHelpers provide the possibility to read the current position within the PDF document.

<pdf:text>This text will be rendered at position x={pdf:getPosX()} and y={pdf:getPosY()}</pdf:text>
Copied!

It is possible to use these ViewHelpers to position elements relatively when used together with a math ViewHelper. The following example requires the extension vhs to be installed.

{namespace v=FluidTYPO3\Vhs\ViewHelpers}

<pdf:text posX="{v:math.subtract(a: '{pdf:getPosX()}', b: 15)}" posY="{v:math.sum(a: '{pdf:getPosY()}', b: 30)}">This text element is moved relatively</pdf:text>
Copied!

TableOfContentViewHelper / HtmlBookmarkTemplateViewHelper

The TableOfContentViewHelper allows to render a table of content when placed inside a PageViewHelper. The HtmlBookmarkTemplateViewHelper allows to style the content table entries using HTML. Text rendered with a HeadlineViewHelper can be added to the table of content automatically by setting plugin.tx_pdfviewhelpers.settings.headline.addToTableOfContent = 1. Additionally it is possible to use the BookmarkViewHelper to add entries to the table of content.

Note that the TableOfContentViewHelper should be placed on the last page of the document, using the page attribute it can be moved to the front. Please see the examples section for an extended example of the table of content usage.

IMPORTANT NOTICE: Please note that TCPDF does not produce valid PDF documents when bookmarks are used. Although most PDF viewers are still able to render the document you might run into validity troubles using these ViewHelpers.

Regular Mode

<pdf:page tableOfContentPage="1">
<pdf:tableOfContent />

</pdf:page>

HTML Mode

In HTML mode the variables #TOC_DESCRIPTION# and #TOC_PAGE_NUMBER# get replaced with the bookmark title and the page number respectively.

<pdf:page tableOfContentPage="1">
	<pdf:tableOfContent page="1" name="Index" htmlMode="1">
		<pdf:htmlBookmarkTemplate level="0">
			<table border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td width="155mm">
						<span style="font-size:12pt;">LEVEL 0: #TOC_DESCRIPTION#</span>
					</td>
					<td width="25mm">
						<span style="font-size:12pt;" align="right">#TOC_PAGE_NUMBER#</span>
					</td>
				</tr>
			</table>
		</pdf:htmlBookmarkTemplate>
		<pdf:htmlBookmarkTemplate level="1">
			<table border="0" cellpadding="0" cellspacing="0">
				<tr>
					<td width="5mm">&nbsp;</td>
					<td width="150mm">
						<span style="font-size:12pt;color: #ff642c;">LEVEL 1: #TOC_DESCRIPTION#</span>
					</td>
					<td width="25mm">
						<span style="font-size:12pt;color: #ff642c;" align="right">#TOC_PAGE_NUMBER#</span>
					</td>
				</tr>
			</table>
		</pdf:htmlBookmarkTemplate>
	</pdf:tableOfContent>
</pdf:page>
Copied!

BookmarkViewHelper

This ViewHelper allows to set a custom bookmark that will add an entry to the table of content. Text rendered with a HeadlineViewHelper can be added to the table of content automatically by setting plugin.tx_pdfviewhelpers.settings.headline.addToTableOfContent = 1.

IMPORTANT NOTICE: Please note that TCPDF does not produce valid PDF documents when bookmarks are used. Although most PDF viewers are still able to render the document you might run into validity troubles using these ViewHelpers.

Basic Usage

<pdf:bookmark text="Adding custom bookmark" />

<pdf:bookmark>Adding custom bookmark</pdf:bookmark>

Advanced Usage

<pdf:bookmark text="Adding custom bookmark" level="1" fontStyle="bold" color="#ff642c" />

AttachPdfViewHelper

This ViewHelper allows to import all pages of an existing PDF document.

<pdf:document>
	<pdf:attachPdf path="EXT:pdfviewhelpers/Resources/Public/Examples/ExtendExistingPDFs/pdf_template.pdf" />
</pdf:document>
Copied!

Basic Usage

TypoScript

pdfpage = PAGE
pdfpage {
	10 = FLUIDTEMPLATE
	10 {
		file = EXT:pdfviewhelpers/Resources/Public/Examples/BasicUsage/Template.html
	}
	# ensure there is no other output apart from the pdf
	# take a look at the generated pdf file (end!) in a text editor to verify there is no other output
	# like warnings, error messages or html code
	config {
		disableAllHeaderCode = 1
		xhtml_cleaning = 0
		admPanel = 0
	}
}

plugin.tx_pdfviewhelpers.settings {
	config {
		language = eng
	}
	document {
		title = Bithost document
		subject = Autogenerated PDF, By Bithost GmbH
		author = Bithost GmbH
		keywords = Example, Test, Just to show how it works
		creator = TYPO3 EXT:pdfviewhelpers
		outputPath = bithost_example.pdf
	}
	header {
		posY = 15
	}
	footer {
		posY = -15
	}
	text {
		paragraphSpacing = 0
	}
	page {
		margin {
			top = 65
			bottom = 25
		}
	}
	graphics {
		line {
			padding {
				top = 0
				bottom = 1.5
			}
		}
	}
}

module.tx_pdfviewhelpers < plugin.tx_pdfviewhelpers
Copied!

Fluid Template

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
	xmlns:pdf="http://typo3.org/ns/Bithost/Pdfviewhelpers/ViewHelpers"
	xsi:schemaLocation="http://typo3.org/ns/Bithost/Pdfviewhelpers/ViewHelpers https://pdfviewhelpers.bithost.ch/schema/3.0.xsd"
	data-namespace-typo3-fluid="true">

<pdf:document outputDestination="inline" title="Bithost Example">
	<pdf:header>
		<pdf:image src="EXT:pdfviewhelpers/Resources/Public/Examples/BasicUsage/logo.png" width="40"/>
		<pdf:text alignment="right" color="#8C8C8C" paragraphSpacing="0" posY="15">
			Bithost GmbH
			Milchbuckstrasse 83
			CH-8057 Zürich

			hallo@bithost.ch
			044 585 28 20

			www.bithost.ch
		</pdf:text>
	</pdf:header>
	<pdf:footer>
		<pdf:graphics.line style="{color: '#8C8C8C'}"/>
		<pdf:text color="#8C8C8C">Page {pdf:getPageNumberAlias()}</pdf:text>
		<pdf:text alignment="right" color="#8C8C8C" posY="-13.5">EXT:pdfviewhelpers - Basic usage example</pdf:text>
	</pdf:footer>

	<pdf:page>
		<pdf:text posY="50" padding="{bottom: 4}" color="#8C8C8C">
			Zurich, <f:format.date format="d.m.Y" >now</f:format.date>
		</pdf:text>
		<pdf:headline>Welcome to the extension pdfviewhelpers</pdf:headline>
		<pdf:text>
			Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr.
			Sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.
		</pdf:text>
		<pdf:headline>Some more information</pdf:headline>

		<pdf:multiColumn>
			<pdf:column width="55%">
				<pdf:text>
					Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua:
				</pdf:text>
				<pdf:list listElements="{0: 'Full Stack Application Development', 1: 'Modernizing, Refactoring and Migrating Applications', 2: 'Active Collaboration in an existing Team', 3: 'Consulting and Support for IT Projects'}"/>
				<pdf:text>
					Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren est Lorem ipsum dolor sit amet.
				</pdf:text>
			</pdf:column>
			<pdf:column width="45%" padding="{left: 2}">
				<pdf:image src="EXT:pdfviewhelpers/Resources/Public/Examples/BasicUsage/Bithost.jpg" />
				<pdf:text padding="{top: 1}" color="#8C8C8C">Esteban Gehring, Markus Mächler</pdf:text>
			</pdf:column>
		</pdf:multiColumn>

		<pdf:text padding="{top: 2}">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</pdf:text>
	</pdf:page>
</pdf:document>

</html>

Copied!

PDF Output

Basic Usage Example

|

Extend Existing PDFs

Intro

There is the possibility to load existing PDF documents and use them as template. Under the hood pdfviewhelpers uses FPDI to import PDF documents as template. You must include the static TypoScript template of the extension in order to make this example work.

TypoScript

pdfpage = PAGE
pdfpage {
	10 = FLUIDTEMPLATE
	10 {
		file = EXT:pdfviewhelpers/Resources/Public/Examples/ExtendExistingPDFs/Template.html
	}
	# ensure there is no other output apart from the pdf
	# take a look at the generated pdf file (end!) in a text editor to verify there is no other output
	# like warnings, error messages or html code
	config {
		disableAllHeaderCode = 1
		xhtml_cleaning = 0
		admPanel = 0
	}
}
Copied!

Fluid Template

<html xmlns="http://www.w3.org/1999/xhtml"
	  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	  xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
	  xmlns:pdf="http://typo3.org/ns/Bithost/Pdfviewhelpers/ViewHelpers"
	  xsi:schemaLocation="http://typo3.org/ns/Bithost/Pdfviewhelpers/ViewHelpers https://pdfviewhelpers.bithost.ch/schema/3.0.xsd"
	  data-namespace-typo3-fluid="true">

<pdf:document sourceFile="EXT:pdfviewhelpers/Resources/Public/Examples/ExtendExistingPDFs/pdf_template.pdf">
	<pdf:page importPage="1" margin="{top: 80, right: 20, bottom: 40, left: 20}">
		<pdf:headline>Here is your header</pdf:headline>
		<pdf:text>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt.</pdf:text>
		<pdf:html autoHyphenation="1">
			<h1 style="font-weight: normal; font-size: 16px;">Here is the HTML header</h1>
			<p>Lorem ipsum dolor sit amet, consetetur
				sadipscingelitrseddiamnonumyeirmodtemporinviduntutlaboreetdoloremagnaaliquyameratseddiam
				voluptua. At vero eos et dolores et ea rebum. Stet
				clita kasd gubergren, no sea takimata sanctus est
				Lorem ipsum dolor sit amet. Lorem ipsum dolor sit
				diam nonumy eirmod tempor invidunt ut labore et
				dolore magna aliquyam erat, sed diam voluptua. At
				vero eos et accusam et justo duo dolores et ea
				rebum. Stet clita kasd gubergren est Lorem ipsum
				dolor sit amet.</p>
			<p>Lorem ipsum dolor sit amet, consetetur sadipscing
				elitr, sed diam nonumy eirmod tempor invidunt ut
				labore et dolore magna aliquyam erat, sed diam
				voluptua. At vero eos et dolores et ea rebum. Stet
				clita kasd gubergren, no sea takimata sanctus est
				Lorem ipsum dolor sit amet. Lorem ipsum dolor sit
				diam nonumy eirmod tempor invidunt ut labore et
				dolore magna aliquyam erat, sed diam voluptua. At
				vero eos et accusam et justo duo dolores et ea
				rebum. Stet clita kasd gubergren est Lorem ipsum
				dolor sit amet.</p>
		</pdf:html>
	</pdf:page>
</pdf:document>

</html>
Copied!

PDF Output

Extend Existing PDFs Example

|

Table Of Content

IMPORTANT NOTICE: Please note that TCPDF does not produce valid PDF documents when bookmarks are used. Although most PDF viewers are still able to render the document you might run into validity troubles using these ViewHelpers.

TypoScript

pdfpage = PAGE
pdfpage {
	10 = FLUIDTEMPLATE
	10 {
		file = EXT:pdfviewhelpers/Resources/Public/Examples/TableOfContent/Template.html
	}
	# ensure there is no other output apart from the pdf
	# take a look at the generated pdf file (end!) in a text editor to verify there is no other output
	# like warnings, error messages or html code
	config {
		disableAllHeaderCode = 1
		xhtml_cleaning = 0
		admPanel = 0
	}
}

plugin.tx_pdfviewhelpers.settings {
	headline {
		addToTableOfContent = 1
	}
}

module.tx_pdfviewhelpers < plugin.tx_pdfviewhelpers

Copied!

Fluid Template

<html xmlns="http://www.w3.org/1999/xhtml"
	  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	  xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
	  xmlns:pdf="http://typo3.org/ns/Bithost/Pdfviewhelpers/ViewHelpers"
	  xsi:schemaLocation="http://typo3.org/ns/Bithost/Pdfviewhelpers/ViewHelpers https://pdfviewhelpers.bithost.ch/schema/3.0.xsd"
	  data-namespace-typo3-fluid="true">

<pdf:document outputDestination="inline">
	<pdf:header>
		<pdf:text>General Header</pdf:text>
	</pdf:header>
	<pdf:footer posY="-20">
		<pdf:text>General Footer</pdf:text>
	</pdf:footer>

	<pdf:page>
		<pdf:headline>Headline page 1</pdf:headline>

		<pdf:pageBreak />

		<pdf:headline>Headline page 2</pdf:headline>
		<pdf:headline tableOfContentLevel="1">Headline page 2, level 1</pdf:headline>
		<pdf:headline tableOfContentLevel="2">Headline page 2, level 2</pdf:headline>

		<pdf:pageBreak />

		<pdf:headline addToTableOfContent="0">Headline not in table of content</pdf:headline>

		<pdf:bookmark level="0" text="Adding custom styled bookmark for a text" />
		<pdf:text>Here is some text.</pdf:text>

		<pdf:bookmark level="0" fontStyle="B" color="#999">Adding custom styled ADVANCED bookmark for a text</pdf:bookmark>
		<pdf:text>Here is some more text.</pdf:text>
	</pdf:page>

	<pdf:page tableOfContentPage="1">
		<pdf:header>
			<pdf:text color="#8C8C8C">regular-table-of-content-header</pdf:text>
		</pdf:header>
		<pdf:footer>
			<pdf:text color="#8C8C8C">regular-table-of-content-footer</pdf:text>
		</pdf:footer>

		<pdf:headline addToTableOfContent="0">Regular table of content</pdf:headline>
		<pdf:tableOfContent page="1" name="Index" />
	</pdf:page>

	<pdf:page tableOfContentPage="1">
		<pdf:header>
			<pdf:text color="#8C8C8C">html-table-of-content-header</pdf:text>
		</pdf:header>
		<pdf:footer>
			<pdf:text color="#8C8C8C">html-table-of-content-footer</pdf:text>
		</pdf:footer>

		<pdf:headline addToTableOfContent="0">HTML Table of content</pdf:headline>
		<pdf:tableOfContent page="1" name="Index" htmlMode="1">
			<pdf:htmlBookmarkTemplate level="0">
				<table border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td width="155mm">
							<span style="font-size:12pt;">LEVEL 0: #TOC_DESCRIPTION#</span>
						</td>
						<td width="25mm">
							<span style="font-size:12pt;" align="right">#TOC_PAGE_NUMBER#</span>
						</td>
					</tr>
				</table>
			</pdf:htmlBookmarkTemplate>
			<pdf:htmlBookmarkTemplate level="1">
				<table border="0" cellpadding="0" cellspacing="0">
					<tr>
						<td width="5mm">&nbsp;</td>
						<td width="150mm">
							<span style="font-size:12pt;color: #ff642c;">LEVEL 1: #TOC_DESCRIPTION#</span>
						</td>
						<td width="25mm">
							<span style="font-size:12pt;color: #ff642c;" align="right">#TOC_PAGE_NUMBER#</span>
						</td>
					</tr>
				</table>
			</pdf:htmlBookmarkTemplate>
		</pdf:tableOfContent>
	</pdf:page>
</pdf:document>

</html>

Copied!

PDF Output

Table of content example output

|

Table of content example output

|

Table of content example output

|

Table of content example output

|

Table of content example output

|

Full Feature Show Case

Intro

This example is showing some of the features of the extension pdfviewhelpers including typography, custom fonts, header and footer, lists, images, html, layout and settings inheritance.

TypoScript

pdfpage = PAGE
pdfpage {
	10 = FLUIDTEMPLATE
	10 {
		file = EXT:pdfviewhelpers/Resources/Public/Examples/FullFeatureShowCase/Template.html
	}
	# ensure there is no other output apart from the pdf
	# take a look at the generated pdf file (end!) in a text editor to verify there is no other output
	# like warnings, error messages or html code
	config {
		disableAllHeaderCode = 1
		xhtml_cleaning = 0
		admPanel = 0
	}
}

plugin.tx_pdfviewhelpers.settings {
	config {
		class = Bithost\Pdfviewhelpers\Model\FullFeatureShowCase
		jpgQuality = 80
		fonts {
			addTTFFont {
				roboto {
					path = EXT:pdfviewhelpers/Resources/Public/Examples/FullFeatureShowCase/Roboto.ttf
				}
				opensans {
					path = EXT:pdfviewhelpers/Resources/Public/Examples/FullFeatureShowCase/OpenSans.ttf
				}
			}
		}
	}
	document {
		title = Full Feature Show Case Title
		subject = No Subject
		keywords = full, feature, show, case
		outputDestination = inline
		outputPath = fullfeatureshowcase.pdf
	}
	header {
		posY = 10
	}
	page {
		margin {
			top = 25
			right = 15
			bottom = 25
			left = 15
		}
	}
	generalText {
		color = #555
	}
	text {
		types {
			header {
				color = #8C8C8C
			}
			quote {
				fontStyle = italic
				alignment = center
				padding {
					top = 10
					right = 50
					bottom = 10
					left = 50
				}
			}
		}
	}
	headline {
		fontFamily = courier
		fontStyle = bold
		types {
			h1 {
				fontSize = 28
				color = #ff642c
			}
			h2 {
				fontSize = 22
				color = #ff642c
			}
			h3 {
				fontSize = 14
				fontFamily = helvetica
				fontStyle = bold
			}
		}
	}
	list {
		color = #000
		fontStyle = bold
		bulletColor = #BEDB39
		padding {
			left = 2
		}
	}
}

module.tx_pdfviewhelpers < plugin.tx_pdfviewhelpers


Copied!

PHP

<?php

namespace Bithost\Pdfviewhelpers\Model;

/***
 *
 * This file is part of the "PDF ViewHelpers" Extension for TYPO3 CMS.
 *
 *  (c) 2016 Markus Mächler <markus.maechler@bithost.ch>, Bithost GmbH
 *           Esteban Gehring <esteban.gehring@bithost.ch>, 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!
 ***/

/**
 * FullFeatureShowCase
 *
 * @author Markus Mächler <markus.maechler@bithost.ch>, Esteban Gehring <esteban.gehring@bithost.ch>
 */
class FullFeatureShowCase extends BasePDF
{
	/**
	 * @return void
	 */
	public function basePdfHeader()
	{
	}

	/**
	 * @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');
	}
}

Copied!

Fluid Template

<html xmlns="http://www.w3.org/1999/xhtml"
	  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	  xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
	  xmlns:pdf="http://typo3.org/ns/Bithost/Pdfviewhelpers/ViewHelpers"
	  xsi:schemaLocation="http://typo3.org/ns/Bithost/Pdfviewhelpers/ViewHelpers https://pdfviewhelpers.bithost.ch/schema/3.0.xsd"
	  data-namespace-typo3-fluid="true">

<pdf:document outputPath="overwritten_name.pdf" title="Full Feature Show Case">

	<pdf:header>
		<pdf:text type="header">Bithost GmbH - Milchbuckstrasse 83 CH-8057 Zürich</pdf:text>
		<pdf:text type="header" posY="10" alignment="right">hallo@bithost.ch - www.bithost.ch</pdf:text>
		<pdf:graphics.line style="{color: '#8C8C8C'}"/>
	</pdf:header>

	<pdf:page>
		<pdf:headline fontSize="20">Full Feature Show Case</pdf:headline>
		<pdf:text>Showing some features of pdfviewhelpers.</pdf:text>

		<pdf:headline>Typography</pdf:headline>
		<pdf:text fontStyle="bold">Bold text</pdf:text>
		<pdf:text fontStyle="italic">Italic text</pdf:text>
		<pdf:text fontStyle="underline">Underlined text</pdf:text>
		<pdf:text color="#ff642c">Colored text</pdf:text>
		<pdf:text alignment="left">Alignment Left</pdf:text>
		<pdf:text alignment="center">Alignment Center</pdf:text>
		<pdf:text alignment="right">Alignment Right</pdf:text>

		<pdf:text color="#ff642c" padding="{top:6, right:80, bottom:6, left:20}">
			Text with special padding. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et dolores et ea rebum.
		</pdf:text>

		<pdf:multiColumn>
			<pdf:column>
				<pdf:text>
					Text with normal paragraph spacing.
					Shown here.
				</pdf:text>
			</pdf:column>
			<pdf:column>
				<pdf:text paragraphSpacing="2">
					Text with extended paragraph spacing.
					Shown here.
				</pdf:text>
			</pdf:column>
			<pdf:column>
				<pdf:text paragraphSpacing="4">
					Text with even more extended paragraph spacing.
					Shown here.
				</pdf:text>
			</pdf:column>
		</pdf:multiColumn>

		<pdf:multiColumn>
			<pdf:column>
				<pdf:text autoHyphenation="0" padding="{right: 2}">
					ThisisalongtextWITHOUTautomatichyphenationbeingactivated.
				</pdf:text>
			</pdf:column>
			<pdf:column>
				<pdf:text autoHyphenation="1" padding="{left: 2}">
					ThisisalongtextWITHautomatichyphenationbeingactivated.
				</pdf:text>
			</pdf:column>
		</pdf:multiColumn>

		<pdf:text lineHeight="2" characterSpacing="1.5">
			This text has increased lineHeight as well as increased characterSpacing.
		</pdf:text>

		<pdf:headline>Custom fonts</pdf:headline>
		<pdf:text fontFamily="opensans">Custom font Open Sans automatically converted from TTF file.</pdf:text>
		<pdf:text fontFamily="roboto">Custom font Roboto automatically converted from TTF file.</pdf:text>
		<pdf:text fontFamily="roboto" color="#ff642c">Custom font Roboto even colored!</pdf:text>

		<pdf:pageBreak />

		<pdf:headline>Styled lists</pdf:headline>
		<pdf:list
				padding="{left: 1.75}"
				bulletSize="2.5"
				bulletImageSrc="EXT:pdfviewhelpers/Resources/Public/Examples/FullFeatureShowCase/bullet_image.png"
				listElements="{0: 'Full Stack Application Development', 1: 'Modernizing, Refactoring and Migrating Applications', 2: 'Active Collaboration in an existing Team', 3: 'Consulting and Support for IT Projects'}" />
		<pdf:list
				bulletSize="2"
				bulletColor="#ff642c"
				fontStyle="italic"
				listElements="{0: 'Lorem ipsum', 1: 'dolor sit', 2: 'Lorem dipsum', 3: 'dolor sit amet'}" />

		<pdf:headline>Text types</pdf:headline>
		<pdf:text>It is possible to create an arbitrary amount of default text settings and easily apply them using the type attribute.</pdf:text>
		<pdf:headline type="h1">This is a h1 headline</pdf:headline>
		<pdf:headline type="h2">This is a h2 headline</pdf:headline>
		<pdf:headline type="h3">This is a h3 headline</pdf:headline>

		<pdf:text type="quote">This could be a quote style. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</pdf:text>
	</pdf:page>

	<pdf:page orientation="landscape" format="A4" margin="{top: 15}">
		<pdf:header scope="thisPage">
			<pdf:text type="header">Only this page will have a different header</pdf:text>
		</pdf:header>

		<pdf:multiColumn>
			<pdf:column width="50%">
				<pdf:headline>Images in different sizes</pdf:headline>
				<pdf:image src="EXT:pdfviewhelpers/Resources/Public/Examples/FullFeatureShowCase/Bithost.jpg" width="100" link="https://www.bithost.ch" />
				<pdf:image src="EXT:pdfviewhelpers/Resources/Public/Examples/FullFeatureShowCase/Bithost.jpg" width="70" link="https://www.bithost.ch" />
				<pdf:image src="EXT:pdfviewhelpers/Resources/Public/Examples/FullFeatureShowCase/Bithost.jpg" width="50" link="https://www.bithost.ch" />
			</pdf:column>
			<pdf:column width="50%">
				<pdf:headline>Images with different alignment</pdf:headline>
				<pdf:image src="EXT:pdfviewhelpers/Resources/Public/Examples/FullFeatureShowCase/Bithost.jpg" width="50%" alignment="left" />
				<pdf:image src="EXT:pdfviewhelpers/Resources/Public/Examples/FullFeatureShowCase/Bithost.jpg" width="50%" alignment="center" />
				<pdf:image src="EXT:pdfviewhelpers/Resources/Public/Examples/FullFeatureShowCase/Bithost.jpg" width="50%" alignment="right" />
			</pdf:column>
		</pdf:multiColumn>
	</pdf:page>

	<pdf:page>
		<pdf:headline>HTML content being styled externally</pdf:headline>
		<pdf:html styleSheet="EXT:pdfviewhelpers/Resources/Public/Examples/FullFeatureShowCase/styles.css">
			<h1>Headline 1</h1>
			<h2>Headline 2</h2>
			<h3>Headline 3</h3>

			<a href="https://www.bithost.ch">A Link to click</a>

			<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>
			<p>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua.</p>

			<h3 style="color: #333;">Table</h3>
			<table cellpadding="4" cellspacing="4">
				<thead>
					<tr>
						<th>Head 1</th>
						<th>Head 2</th>
						<th>Head 3</th>
					</tr>
				</thead>
				<tbody>
					<tr>
						<td>Content 1</td>
						<td>Content 2</td>
						<td>Content 3</td>
					</tr>
					<tr>
						<td>More Content 1</td>
						<td>More Content 2</td>
						<td>More Content 3</td>
					</tr>
					<tr>
						<td>Content 1</td>
						<td>Content 2</td>
						<td>Content 3</td>
					</tr>
				</tbody>
			</table>
		</pdf:html>

		<pdf:headline>Position ViewHelpers</pdf:headline>
		<pdf:text>This text will be rendered at position x={pdf:getPosX()} and y={pdf:getPosY()}</pdf:text>

		<pdf:headline>PageNumber ViewHelpers</pdf:headline>
		<pdf:text>We are on page {pdf:getPageNumberAlias()} of {pdf:getTotalNumberOfPagesAlias()} pages.</pdf:text>

		<pdf:avoidPageBreakInside>
			<pdf:headline>Avoid page break inside</pdf:headline>
			<pdf:text>EXT:pdfviewhelpers tries to avoid page breaks inside ViewHelpers that are wrapped with an AvoidPageBreakInsideViewHelper.</pdf:text>
			<pdf:text>Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet. Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</pdf:text>
			<pdf:text>That is why all these elements are rendered on the next page.</pdf:text>
		</pdf:avoidPageBreakInside>
	</pdf:page>

</pdf:document>

</html>
Copied!

PDF Output

Full Feature Show Case rendered PDF

|

Full Feature Show Case rendered PDF

|

Full Feature Show Case rendered PDF

|

Full Feature Show Case rendered PDF

|

Full Feature Show Case rendered PDF

|

PDF/A Show Case

Intro

Its's possible to render the output as a valid PDF/A document.

TypoScript

Be sure to disable all header data, to ensure that all HTML header output is disabled. Some variables on page properties are used to fill the meta data. The most important setting is plugin.tx_pdfviewhelpers.settings.document.pdfa = 1 to enable PDF/A mode.

pdfpage = PAGE
pdfpage {

	config {
		disableAllHeaderCode = 1
		xhtml_cleaning = 0
		admPanel = 0
	}

	10 = FLUIDTEMPLATE
	10 {
		file = EXT:pdfviewhelpers/Resources/Public/Examples/PdfaShowCase/Template.html
		variables {
			fileTitle = TEXT
			fileTitle {
				field = title
				wrap = |.pdf
			}

			docTitle = TEXT
			docTitle {
				field = title
				wrap = |
			}

			docAuthor = TEXT
			docAuthor {
				field = author
				wrap = |
			}

			docDate = TEXT
			docDate {
				field = starttime
				date = d.m.Y
				wrap = |
			}

			docAbstract = TEXT
			docAbstract {
				field = abstract
				wrap = |
			}

			docKeywords = TEXT
			docKeywords {
				field = keywords
				wrap = |
			}
		}
	}
}

plugin.tx_pdfviewhelpers.settings {
	config {
		class = Bithost\Pdfviewhelpers\Model\PdfaShowCase
		jpgQuality = 80
		fonts {
			addTTFFont {
				roboto {
					path = EXT:pdfviewhelpers/Resources/Public/Examples/FullFeatureShowCase/Roboto.ttf
				}
				opensans {
					path = EXT:pdfviewhelpers/Resources/Public/Examples/FullFeatureShowCase/OpenSans.ttf
				}
			}
		}
	}
	document {
		title = PDFa Show Case Title
		subject = No Subject
		keywords = full, feature, show, case
		outputDestination = I
		outputPath = pdfa.pdf
		pdfa = 1
	}
	page {
		margin {
			top = 20
			right = 15
			bottom = 20
			left = 15
		}
	}
	generalText {
		color = #555
	}
	headline {
		fontFamily = courier
		fontStyle = B
	}
	list {
		color = #555
		fontStyle = I
		bulletColor = #555
	}
}

module.tx_pdfviewhelpers < plugin.tx_pdfviewhelpers
Copied!

Fluid Template

<html xmlns="http://www.w3.org/1999/xhtml"
	  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	  xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers"
	  xmlns:pdf="http://typo3.org/ns/Bithost/Pdfviewhelpers/ViewHelpers"
	  xsi:schemaLocation="http://typo3.org/ns/Bithost/Pdfviewhelpers/ViewHelpers https://pdfviewhelpers.bithost.ch/schema/3.0.xsd"
	  data-namespace-typo3-fluid="true">

<pdf:document outputDestination="inline" outputPath="{fileTitle}" author="{docAuthor}" title="{docTitle}" creator="PDF View Helpers" keywords="{docKeywords}" subject="{docAbstract}">
	<pdf:page autoPageBreak="0">
		<pdf:headline trim="0" color="#333" fontSize="18" fontStyle="regular" alignment="left" >Lorem ipsum dolor sit amet</pdf:headline>
		<pdf:text>
			Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et dolores et ea rebum.
		</pdf:text>
	</pdf:page>
</pdf:document>

</html>
Copied!

Standalone Rendering

It is possible to render a PDF document as standalone view. That is especially useful if you want to attach the document to an email or you want to generate multiple PDFs in one request.

PHP

<?php
$standaloneView = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Fluid\View\StandaloneView::class);
$templatePath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('EXT:pdfviewhelpers/Resources/Public/Examples/BasicUsage/Template.html');

$standaloneView->setFormat('html');
$standaloneView->setTemplatePathAndFilename($templatePath);
$standaloneView->assignMultiple(['someVariable' => 'someValue']);

$pdf = $standaloneView->render(); //return pdf as string, or simply save to file system

Copied!

Fluid Template - return PDF as String

{namespace pdf=Bithost\Pdfviewhelpers\ViewHelpers}

<pdf:document outputDestination="string">
	<pdf:page>
		<pdf:text>Your content - {someVariable}</pdf:text>
	</pdf:page>
</pdf:document>

Copied!

Fluid Template - return PDF as base64 mime multi-part email attachment (RFC 2045)

{namespace pdf=Bithost\Pdfviewhelpers\ViewHelpers}

<pdf:document outputDestination="email">
	<pdf:page>
		<pdf:text>Your content - {someVariable}</pdf:text>
	</pdf:page>
</pdf:document>

Copied!

Fluid Template - save PDF to file

{namespace pdf=Bithost\Pdfviewhelpers\ViewHelpers}

<pdf:document outputDestination="file" outputPath="fileadmin/document.pdf">
	<pdf:page>
		<pdf:text>Your content - {someVariable}</pdf:text>
	</pdf:page>
</pdf:document>
Copied!

Troubleshooting

Please look carefully at the examples being shipped with this extension, you will find the code in Resources/Public/Examples. Be aware that the static TypoScript template must be included for the examples to work!

Typical Problems

Headers already sent

Sometimes the following error message is found in the php log or in the output:

Warning:

PHP Warning: Cannot modify header information - headers already sent by...
Copied!

This usually occurs when there has already been sent content to the output buffer before the pdf fluid template is rendered. Since we need to set some headers in order to allow the browser to interpret the content as pdf file for inline display / download, pdfviewhelpers need to be able to set headers, and this can only be done if there was no output at all on that page before the pdf is rendered.

PDF does not validate

Sometimes, the generated pdf does not correctly validate e.g. in https://www.pdf-online.com/osa/validate.aspx If this is the case, check the generated file in a text editor, especially the end of the file. Ensure there is no content after the %%EOF.

If you want to have a valid PDF/A document, validate the xml in the metadata in the

Code:

<< /Type /Metadata /Subtype /XML /Length 4505 >> stream
<?xpacket begin="Ôªø" id="W5M0MpCehiHzreSzNTczkc9d"?>
<x:xmpmeta xmlns:x="adobe:ns:meta/" x:xmptk="Adobe XMP Core 4.2.1-c043 52.372728, 2009/01/18-15:08:04">
    <rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#">
        ...
        </rdf:Description>
    </rdf:RDF>
</x:xmpmeta>
<?xpacket end="w"?>
Copied!

Section with e.g. here: https://www.w3schools.com/xml/xml_validator.asp

Also ensure you have disabled all html header output:

pdfpage = PAGE
pdfpage {
	10 = FLUIDTEMPLATE
	10 {
		file = EXT:pdfviewhelpers/Resources/Public/Examples/BasicUsage/Template.html
	}
	# ensure there is no other output apart from the pdf
	# take a look at the generated pdf file (end!) in a text editor to verify there is no other output
	# like warnings, error messages or html code
	config {
		disableAllHeaderCode = 1
		xhtml_cleaning = 0
		admPanel = 0
	}
}

Copied!

pdfviewhelpers can not be installed via TER

The extension pdfviewhelpers is quite big compared to other extensions, as it ships with the entire TCPDF in order to be easily installable via TER. The size EXT:pdfviewhelpers might be an issue if your memory_limit or max_execution_time is quite low, try increasing these values.

PHP

ini_set('max_execution_time', 300);
ini_set('memory_limit', '512M');
Copied!

php.ini

max_execution_time = 300
memory_limit = 512M
Copied!

Upgrading from 1.x.x to 2.x.x

Replaced EmptyFPDI and EmptyTCPDF by BasePDF

The classes EmptyFPDI and EmptyTCPDF have been replaced by BasePDF. If you have any TypoScript configuration or PHP Code using these classes you should replace them by Bithost\Pdfviewhelpers\Model\BasePDF. The class BasePDF offers the same functionality as the other classes before while adding the possibility to use header and footer ViewHelpers.

Provided class must inherit from BasePDF

The PDF class you can provide in plugin.tx_pdfviewhelpers.settings.config.class is now required to inherit from Bithost\Pdfviewhelpers\Model\BasePDF.

Removed example class BithostTCPDF

The example class BithostTCPDF has been removed without a replacement. Please extend BasePDF, and see the basic usage example on how to render a similar header.

Introduces ValidationService

All utility methods that start with isValid have been moved to a separate class ValidationService. If you implemented custom ViewHelpers you have to change these method calls.

Renamed page.margins to page.margin

The TypoScript setting plugin.tx_pdfviewhelpers.settings.page.margins has been renamed to plugin.tx_pdfviewhelpers.settings.page.margin. Also the Fluid PageViewHelper attribute has been renamed from page.margins to page.margin.

Changed default value of page.autoPageBreak

The option plugin.tx_pdfviewhelpers.settings.page.autoPageBreak is now enabled by default.

Moved settings from config to document

The settings plugin.tx_pdfviewhelpers.settings.config.language and plugin.tx_pdfviewhelpers.settings.config.hyphenFile have been moved to plugin.tx_pdfviewhelpers.settings.document.language and plugin.tx_pdfviewhelpers.settings.document.hyphenFile. That allows to set this values in the Fluid template and thus allows to create documents of different languages in a batch process.

Upgrading from 2.x.x to 3.x.x

Removed TCPDF and FPDI libraries from source code

The libraries TCPDF and FPDI have been removed from Resources\Private\PHP for composer installations. In case you are referencing paths in that folder, you might have to change them to the vendor folder.

Removed classes EmptyFPDI and EmptyTCPDF

The deprecated classes PDF Bithost\Pdfviewhelpers\Model\EmptyFPDI and Bithost\Pdfviewhelpers\Model\EmptyTCPDF have been removed. Please use Bithost\Pdfviewhelpers\Model\BasePDF as an alternative.

Type hints and strict typing

The PHP files now use strict types and have been extended with type hinting. This might require changes to classes that inherit or use classes from this extension.

pdfviewhelpers - EXT:news

The TypoScript template pdfviewhelpers - EXT:news does no longer copy the plugin settings to module.tx_pdfviewhelpers and the page config has been moved from config to pageNewsPDF.config.

TypoScript file extensions

All TypoScript file extensions have been changed from .txt to .typoscript.

ImageViewHelper processingInstructions merging

The processingInstructions from TypoScript settings and the Fluid template are now merged instead of overwritten. This might lead to TypoScript settings being applied unexpectedly depending on your usage.