Sf TIC Bundles

DompdfService extends PDFService
in package
Uses DompdfWrapper

Service de génération de PDF avec DomPDF (à partir d'un contenu HMTL ou d'une vue Twig).

Table of Contents

Constants

MIME_TYPES  = array('PDF' => [".pdf", "application/pdf"], 'PNG' => [".png", "image/png"])
Types mimes & extensions de fichiers disponibles

Properties

$confs  : mixed
Valeurs par défaut (options & chemins) pour les générations Twig|HTML vers PDF|PNG
$debug  : mixed
$dompdf  : mixed
$encore  : mixed
$paths  : mixed
$temp_files  : mixed
$twig  : mixed

Methods

__construct()  : mixed
Construction du service en chargeant la configuration des parameters.
__destruct()  : mixed
addInfo()  : void
Add meta information to the PDF after rendering.
construct()  : mixed
Class constructor
enableCaching()  : mixed
Enable experimental caching capability
getBaseHost()  : string
Returns the base hostname
getBasePath()  : string
Returns the base path
getCallbacks()  : array<string|int, mixed>
Returns the callbacks array
getCanvas()  : Canvas
Return the underlying Canvas instance (e.g. Dompdf\Adapter\CPDF, Dompdf\Adapter\GD)
getCss()  : Stylesheet
Returns the stylesheet
getDom()  : DOMDocument
getFontMetrics()  : FontMetrics
getHttpContext()  : resource
Returns the HTTP context
getOptions()  : Options
getPaperOrientation()  : string
Gets the paper orientation
getPaperSize()  : array<string|int, float>
Gets the paper size
getProtocol()  : string
Returns the protocol in use
getQuirksmode()  : bool
Get the quirks mode
getTree()  : FrameTree
Returns the underlying {@link FrameTree} object
initEngine()  : DompdfService
Initialisation de l'objet Dompdf avec ses options.
loadDOM()  : mixed
loadHtml()  : mixed
Loads an HTML string Parse errors are stored in the global array _dompdf_warnings.
loadHtmlData()  : DompdfService
Initialisation de l'objet Dompdf à partir d'un contenu HTML.
loadHtmlFile()  : DompdfService
Initialisation de l'objet Dompdf à partir d'un fichier HTML.
loadTwigView()  : PDFService
Initialisation du moteur html2pdf à partir d'une vue Twig à générer.
metadata()  : DompdfService
Add meta informations to the PDF after rendering
output()  : string|null
Returns the PDF as a string.
outputHtml()  : string
Returns the underlying HTML document as a string
parseDefaultView()  : bool
removeTextNodes()  : mixed
render()  : mixed
Renders the HTML to PDF
renderData()  : string
Returns the PDF data as a string.
renderDirect()  : void
Output the generated PDF to Browser (native Dompdf method).
renderFile()  : string
Returns the PDF in a local file.
renderResponse()  : Response
Returns the PDF in a symfony Response object (clean integration).
renderStream()  : StreamedResponse
Returns the PDF in a symfony StreamedResponse object (less memory usage).
setBaseHost()  : $this
Sets the base hostname
setBasePath()  : $this
Sets the base path
setCallbacks()  : $this
Define callbacks that allow modifying the document during render.
setCanvas()  : $this
Set a custom `Canvas` instance to render the document to.
setCss()  : $this
setDefaultView()  : $this
Sets the default view
setDom()  : $this
setFontMetrics()  : $this
setHttpContext()  : $this
Sets the HTTP context
setOptions()  : $this
setPaper()  : $this
Sets the paper size & orientation
setProtocol()  : $this
Sets the protocol to use FIXME validate these
setTree()  : $this
stream()  : mixed
Streams the PDF to the client.
view2data()  : string
Initialisation à partir d'une vue Twig pour générer un PDF retourné dans une variable.
view2file()  : string
Initialisation à partir d'une vue Twig pour générer un PDF retourné dans un fichier local.
view2http()  : StreamedResponse
Initialisation à partir d'une vue Twig pour générer un PDF retourné dans une StreamedResponse.
createTempFile()  : string
Création d'un fichier temporaire avec le contenu donné.
fixFilename()  : string
fixFilepath()  : string
fixHtmlFile()  : string
fixTwigView()  : string
getFileType()  : array<string|int, mixed>|null
getHttpHeaders()  : array<string|int, mixed>
purgeTempFiles()  : mixed
Suppression des fichiers temporaires (sauf en mode debug).

Constants

MIME_TYPES

Types mimes & extensions de fichiers disponibles

public mixed MIME_TYPES = array('PDF' => [".pdf", "application/pdf"], 'PNG' => [".png", "image/png"])

Properties

$confs

Valeurs par défaut (options & chemins) pour les générations Twig|HTML vers PDF|PNG

protected mixed $confs = array( 'debug' => false, // dump des options, debug CSS et fichier de log 'generator' => "auto", // auto|pdf = PDFLib|CPDF|wkhtmltopdf ; image|png = GD|wkhtmltoimage 'pdflib_license' => null, // [dompdf] si usage de PDFLib avec une licence 'media_type' => "screen", // CSS3 media type: screen | print 'paper_size' => "A4", // page format: A4, letter... 'orientation' => "portrait", // page orientation: portrait | landscape 'default_font' => "DejaVu Sans", // [dompdf] helvetica, times-roman, courier... 'font_ratio' => 1.1, // [dompdf] ratio sur la hauteur (pour rendu proche des navigateurs) 'dpi' => 96, // DPI setting (images & fonts) 'default_twigview' => "layout_print", // nom de la vue twig par défault (sans l'extension ".html.twig") 'default_filename' => "document", // nom du fichier de sortie (sans l'extension ".pdf") 'base_url' => null, )

$paths

protected mixed $paths = array( 'root_dir' => null, // racine des fichiers accessibles en chargement (chroot|allow) 'path_source' => null, // dossier parent par défaut pour les fichiers chargés (HTML) 'path_output' => null, // dossier parent par défaut pour les fichiers générés (PDF|PNG) 'path_logdir' => null, // dossier parent pour les fichiers de log (debug) 'path_tmpdir' => null, // dossier parent pour les fichiers temporaires (défaut sys_get_temp_dir) 'wkhtml_pdf' => __DIR__ . '../../../../bin/wkhtmltopdf-amd64', // [wkhtml] 'wkhtml_image' => __DIR__ . '../../../../bin/wkhtmltoimage-amd64', )

$temp_files

protected mixed $temp_files = array()

Methods

__construct()

Construction du service en chargeant la configuration des parameters.

public __construct([array<string|int, mixed> $confs = [] ][, array<string|int, mixed> $paths = [] ][, Environment $twig = null ][, TranslatorInterface $translator = null ][, EntrypointLookupInterface $encore = null ]) : mixed
Parameters
$confs : array<string|int, mixed> = []

Liste des options pour le paramétrage du service

$paths : array<string|int, mixed> = []

Liste des chemins pour le paramétrage du service

$twig : Environment = null

Instance du moteur de rendu pour générer les vues HTML

$translator : TranslatorInterface = null

Service d'internationalisation pour changer la locale

$encore : EntrypointLookupInterface = null

Accès à la réinitialisation de Webpack Encore

addInfo()

Add meta information to the PDF after rendering.

public addInfo(string $label, string $value) : void
Parameters
$label : string

Label of the value (Creator, Producer, etc.)

$value : string

The text to set

construct()

Class constructor

public construct([Options|array<string|int, mixed>|null $options = null ]) : mixed
Parameters
$options : Options|array<string|int, mixed>|null = null

enableCaching()

Enable experimental caching capability

public enableCaching(string $cacheId) : mixed
Parameters
$cacheId : string

getBaseHost()

Returns the base hostname

public getBaseHost() : string
Return values
string

getBasePath()

Returns the base path

public getBasePath() : string
Return values
string

getCallbacks()

Returns the callbacks array

public getCallbacks() : array<string|int, mixed>
Return values
array<string|int, mixed>

getCanvas()

Return the underlying Canvas instance (e.g. Dompdf\Adapter\CPDF, Dompdf\Adapter\GD)

public getCanvas() : Canvas
Return values
Canvas

getCss()

Returns the stylesheet

public getCss() : Stylesheet
Return values
Stylesheet

getDom()

public getDom() : DOMDocument
Return values
DOMDocument

getFontMetrics()

public getFontMetrics() : FontMetrics
Return values
FontMetrics

getHttpContext()

Returns the HTTP context

public getHttpContext() : resource
Return values
resource

getOptions()

public getOptions() : Options
Return values
Options

getPaperOrientation()

Gets the paper orientation

public getPaperOrientation() : string
Return values
string

Either "portrait" or "landscape"

getPaperSize()

Gets the paper size

public getPaperSize() : array<string|int, float>
Return values
array<string|int, float>

A four-element float array

getProtocol()

Returns the protocol in use

public getProtocol() : string
Return values
string

getQuirksmode()

Get the quirks mode

public getQuirksmode() : bool
Return values
bool

true if quirks mode is active

getTree()

Returns the underlying {@link FrameTree} object

public getTree() : FrameTree
Return values
FrameTree

initEngine()

Initialisation de l'objet Dompdf avec ses options.

public initEngine([array<string|int, mixed> $pdf_options = [] ]) : DompdfService
Parameters
$pdf_options : array<string|int, mixed> = []

Surcharge d'options pour Dompdf

Tags
See

https://github.com/dompdf/dompdf/blob/master/src/Options.php

private $fontDir; private $fontCache; private $chroot; private $allowedProtocols = ["file://" => ["rules" => []], "http://" => ["rules" => []], "https://" => ["rules" => []] private $httpContext;

Return values
DompdfService

loadDOM()

public loadDOM(mixed $doc[, mixed $quirksmode = false ]) : mixed
Parameters
$doc : mixed
$quirksmode : mixed = false

loadHtml()

Loads an HTML string Parse errors are stored in the global array _dompdf_warnings.

public loadHtml(string $str[, string $encoding = null ]) : mixed
Parameters
$str : string

HTML text to load

$encoding : string = null

Encoding of $str

loadHtmlData()

Initialisation de l'objet Dompdf à partir d'un contenu HTML.

public loadHtmlData(string $html_data[, array<string|int, mixed> $pdf_options = [] ]) : DompdfService
Parameters
$html_data : string

Contenu du document HTML à charger

$pdf_options : array<string|int, mixed> = []

Surcharge d'options pour Dompdf

Return values
DompdfService

loadHtmlFile()

Initialisation de l'objet Dompdf à partir d'un fichier HTML.

public loadHtmlFile(string $html_file[, array<string|int, mixed> $pdf_options = [] ]) : DompdfService
Parameters
$html_file : string

Chemin du fichier HTML à charger

$pdf_options : array<string|int, mixed> = []

Surcharge d'options pour Dompdf

Return values
DompdfService

loadTwigView()

Initialisation du moteur html2pdf à partir d'une vue Twig à générer.

public loadTwigView([string $twig_view = null ][, array<string|int, mixed> $view_params = [] ][, array<string|int, mixed> $pdf_options = [] ]) : PDFService

NOTE: avec gestion de la locale et reset de webpack encore (en cas d'usages multiples)

Parameters
$twig_view : string = null

Chemin du template twig à générer

$view_params : array<string|int, mixed> = []

Variables à injecter dans le template (peut contenir 'locale')

$pdf_options : array<string|int, mixed> = []

Surcharge des options du moteur html2pdf

Return values
PDFService

metadata()

Add meta informations to the PDF after rendering

public metadata([array<string|int, mixed> $info = [] ]) : DompdfService
Parameters
$info : array<string|int, mixed> = []

Liste de clés/valeurs pour ajouter des metadata PDF

Return values
DompdfService

output()

Returns the PDF as a string.

public output([array<string|int, mixed> $options = [] ]) : string|null

The options parameter controls the output. Accepted options are:

'compress' = > 1 or 0 - apply content stream compression, this is on (1) by default

Parameters
$options : array<string|int, mixed> = []

options (see above)

Return values
string|null

outputHtml()

Returns the underlying HTML document as a string

public outputHtml() : string
Return values
string

parseDefaultView()

public parseDefaultView(string $value) : bool
Parameters
$value : string
Return values
bool

removeTextNodes()

public static removeTextNodes(DOMNode $node) : mixed
Parameters
$node : DOMNode

renderData()

Returns the PDF data as a string.

public renderData([bool $nocompress = false ]) : string
Parameters
$nocompress : bool = false

Désactivation de la compression PDF

Return values
string

Données binaires du document PDF

renderDirect()

Output the generated PDF to Browser (native Dompdf method).

public renderDirect([string $filename = null ][, bool $inline = false ][, bool $nocompress = false ]) : void
Parameters
$filename : string = null

Nom du document PDF à télécharger

$inline : bool = false

Affichage du PDF sans forcer son enregistrement

$nocompress : bool = false

Désactivation de la compression PDF

renderFile()

Returns the PDF in a local file.

public renderFile([string $filepath = null ][, bool $nocompress = false ]) : string
Parameters
$filepath : string = null

Chemin du fichier PDF à enregistrer

$nocompress : bool = false

Désactivation de la compression PDF

Return values
string

Chemin du fichier PDF généré

renderResponse()

Returns the PDF in a symfony Response object (clean integration).

public renderResponse([string $filename = null ][, bool $inline = false ][, bool $nocompress = false ]) : Response
Parameters
$filename : string = null

Nom du document PDF à télécharger

$inline : bool = false

Affichage du PDF sans forcer son enregistrement

$nocompress : bool = false

Désactivation de la compression PDF

Return values
Response

Objet à retourner par le controlleur

renderStream()

Returns the PDF in a symfony StreamedResponse object (less memory usage).

public renderStream([string $filename = null ][, bool $inline = false ][, bool $nocompress = false ]) : StreamedResponse
Parameters
$filename : string = null

Nom du document PDF à télécharger

$inline : bool = false

Affichage du PDF sans forcer son enregistrement

$nocompress : bool = false

Désactivation de la compression PDF

Return values
StreamedResponse

Objet à retourner par le controlleur

setBaseHost()

Sets the base hostname

public setBaseHost(string $baseHost) : $this
Parameters
$baseHost : string
Return values
$this

setBasePath()

Sets the base path

public setBasePath(string $basePath) : $this
Parameters
$basePath : string
Return values
$this

setCallbacks()

Define callbacks that allow modifying the document during render.

public setCallbacks(array<string|int, mixed> $callbacks) : $this

The callbacks array should contain arrays with event set to a callback event name and f set to a function or any other callable.

The available callback events are:

  • begin_page_reflow: called before page reflow
  • begin_frame: called before a frame is rendered
  • end_frame: called after frame rendering is complete
  • begin_page_render: called before a page is rendered
  • end_page_render: called after page rendering is complete
  • end_document: called for every page after rendering is complete

The function f receives three arguments Frame $frame, Canvas $canvas, and FontMetrics $fontMetrics for all events but end_document. For end_document, the function receives four arguments int $pageNumber, int $pageCount, Canvas $canvas, and FontMetrics $fontMetrics instead.

Parameters
$callbacks : array<string|int, mixed>

The set of callbacks to set.

Return values
$this

setCanvas()

Set a custom `Canvas` instance to render the document to.

public setCanvas(Canvas $canvas) : $this

Be aware that the instance will be replaced on render if the document defines a paper size different from the canvas.

Parameters
$canvas : Canvas
Return values
$this

setCss()

public setCss(Stylesheet $css) : $this
Parameters
$css : Stylesheet
Return values
$this

setDefaultView()

Sets the default view

public setDefaultView(string $defaultView, array<string|int, mixed> $options) : $this
Parameters
$defaultView : string

The default document view

$options : array<string|int, mixed>

The view's options

Return values
$this

setDom()

public setDom(DOMDocument $dom) : $this
Parameters
$dom : DOMDocument
Return values
$this

setFontMetrics()

public setFontMetrics(FontMetrics $fontMetrics) : $this
Parameters
$fontMetrics : FontMetrics
Return values
$this

setHttpContext()

Sets the HTTP context

public setHttpContext(resource|array<string|int, mixed> $httpContext) : $this
Parameters
$httpContext : resource|array<string|int, mixed>
Return values
$this

setOptions()

public setOptions(Options $options) : $this
Parameters
$options : Options
Return values
$this

setPaper()

Sets the paper size & orientation

public setPaper(string|array<string|int, float> $size[, string $orientation = "portrait" ]) : $this
Parameters
$size : string|array<string|int, float>

'letter', 'legal', 'A4', etc.

$orientation : string = "portrait"

'portrait' or 'landscape'

Return values
$this

setProtocol()

Sets the protocol to use FIXME validate these

public setProtocol(string $protocol) : $this
Parameters
$protocol : string
Return values
$this

setTree()

public setTree(FrameTree $tree) : $this
Parameters
$tree : FrameTree
Return values
$this

stream()

Streams the PDF to the client.

public stream([string $filename = "document.pdf" ][, array<string|int, mixed> $options = [] ]) : mixed

The file will open a download dialog by default. The options parameter controls the output. Accepted options (array keys) are:

'compress' = > 1 (=default) or 0: Apply content stream compression

'Attachment' => 1 (=default) or 0: Set the 'Content-Disposition:' HTTP header to 'attachment' (thereby causing the browser to open a download dialog)

Parameters
$filename : string = "document.pdf"

the name of the streamed file

$options : array<string|int, mixed> = []

header options (see above)

view2data()

Initialisation à partir d'une vue Twig pour générer un PDF retourné dans une variable.

public view2data([string $twig_view = null ][, array<string|int, mixed> $view_params = [] ][, array<string|int, mixed> $pdf_options = [] ]) : string
Parameters
$twig_view : string = null

Chemin du template twig à générer

$view_params : array<string|int, mixed> = []

Variables à injecter dans le template (peut contenir 'locale')

$pdf_options : array<string|int, mixed> = []

Surcharge des options du moteur html2pdf

Return values
string

Données binaires du document PDF

view2file()

Initialisation à partir d'une vue Twig pour générer un PDF retourné dans un fichier local.

public view2file(string $filepath[, string $twig_view = null ][, array<string|int, mixed> $view_params = [] ][, array<string|int, mixed> $pdf_options = [] ]) : string
Parameters
$filepath : string

Chemin du fichier PDF à enregistrer

$twig_view : string = null

Chemin du template twig à générer

$view_params : array<string|int, mixed> = []

Variables à injecter dans le template (peut contenir 'locale')

$pdf_options : array<string|int, mixed> = []

Surcharge des options du moteur html2pdf

Return values
string

Chemin du fichier PDF généré

view2http()

Initialisation à partir d'une vue Twig pour générer un PDF retourné dans une StreamedResponse.

public view2http(string $filename[, string $twig_view = null ][, array<string|int, mixed> $view_params = [] ][, array<string|int, mixed> $pdf_options = [] ]) : StreamedResponse
Parameters
$filename : string

Nom du document PDF à télécharger

$twig_view : string = null

Chemin du template twig à générer

$view_params : array<string|int, mixed> = []

Variables à injecter dans le template (peut contenir 'locale')

$pdf_options : array<string|int, mixed> = []

Surcharge des options du moteur html2pdf

Return values
StreamedResponse

Objet à retourner par le controlleur

createTempFile()

Création d'un fichier temporaire avec le contenu donné.

protected createTempFile([string $prefix = "" ][, string $suffix = null ][, string $file_data = null ]) : string
Parameters
$prefix : string = ""

Chaine pour le début du nom du fichier (sous-dossier si commence par un /)

$suffix : string = null

Chaine à utiliser comme extension du nom du fichier

$file_data : string = null

Contenu à placer dans le fichier à générer

Return values
string

Chemin absolu du fichier temporaire (généré/à générer)

fixFilename()

protected fixFilename([string|null $filename = null ][, string|null $extension = null ]) : string
Parameters
$filename : string|null = null
$extension : string|null = null
Return values
string

fixFilepath()

protected fixFilepath([string|null $filepath = null ]) : string
Parameters
$filepath : string|null = null
Return values
string

fixHtmlFile()

protected fixHtmlFile(string $html_file) : string
Parameters
$html_file : string
Return values
string

fixTwigView()

protected fixTwigView([string|null $twig_view = null ]) : string
Parameters
$twig_view : string|null = null
Return values
string

getFileType()

protected getFileType([string $type = "PDF" ]) : array<string|int, mixed>|null
Parameters
$type : string = "PDF"
Return values
array<string|int, mixed>|null

getHttpHeaders()

protected getHttpHeaders([string|null $filename = null ][, bool $inline = false ]) : array<string|int, mixed>
Parameters
$filename : string|null = null
$inline : bool = false
Return values
array<string|int, mixed>

purgeTempFiles()

Suppression des fichiers temporaires (sauf en mode debug).

protected purgeTempFiles() : mixed

        
On this page

Search results