Skip to content
This repository has been archived by the owner. It is now read-only.
Create PDF on the fly with this flexible MODx snippet
Branch: master
Clone or download
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs Added the possibility to decide to print a header and/or footer. Nov 13, 2011
htmlToPDF - Added current TCPDF version. That version corrected a bug with curl Mar 26, 2012
media Added PhpDoc Feb 12, 2012
nbproject Added phpdoc Feb 12, 2012
.gitignore Added the possibility to decide to print a header and/or footer. Nov 13, 2011 The repository is not maintained anymore. Jan 22, 2018
blank.html Added phpdoc Feb 12, 2012
classtrees_htmlToPDF.html Added phpdoc Feb 12, 2012
elementindex_htmlToPDF.html Added phpdoc Feb 12, 2012
errors.html Added phpdoc Feb 12, 2012
index.html Added phpdoc Feb 12, 2012
install.txt Updated to the current TCPDF version 5.9.145. Feb 12, 2012
li_htmlToPDF.html Added phpdoc Feb 12, 2012
license.txt Renamed readme.txt to license.txt because the file contains only the … Feb 28, 2011
packages.html Added phpdoc Feb 12, 2012
readme.txt Updated to the current TCPDF version 5.9.145. Feb 12, 2012

This repository will not be maintained anymore

I don't work with MODX anymore.


This package contains source for an HTML to PDF converter for MODX Evolution, which is available at the MODX Website

Currently it is not planned to create a copy for MODX Revolution.

If you use Microsoft Windows in any version, please notice, that all files of this project have UNIX based line breaks.

You find news about this project on my site at, the news feed is available at


The source is licensed under the GNU Lesser General Public License, version 2.1 as published at

###Usage of TCPDF###

This MODX snippet uses TCPDF, available at, to create the PDF Files from the content of a web document, published with MODX. TCPDF is part of the package. TCPDF itself is licensed under LGPL V3, as described at The current version of TCPDF used in this package is 5.9.145.

The main goal is to create highly configurable PDF documents. This is possible with parameters that one can use in the snippet tag and through the usage of chunks. All chunks make use of the placeholders as defined in other MODX snippets.


###Upload### For the installation you need to upload the TCPDF in the directory:


The snippet classes should be located at:


###Create the snippet htmlToPDF### Create a new snippet with the source of snippet.hmtlToPDF.php and call the snippet within your templates, probably at the top of the template. For the snippet call you can add several chunks as templates. Examples are in the assets/snippets/htmlToPDF/chunks/ directory.

###Create the plugin htmlToPDF### Create a new plugin with the source of plugin.htmlToPDF. On the page "System Events" choose these two options in the area "Documents":

  • OnBeforeDocFormDelete
  • OnDocFormSave

###Example Snippet Call###

Here is an example for a call to htmlToPDF:

    &author=``Stefanie Janine Stoelting``  

###How to call the snippet###

Place the snippet in the template of the document, where you want your readers to download the content as PDF. The advantage is, that you only have one call for all your documents.

If you have documents where that you do not want to publish as PDF and you only want to use one template, than try it with a template variable (TV) for this and PHX for the call and put your call to htmlToPDF into a snippet:


Where printPDF ist a possible name for the TV and snippetCAllhtmlToPDF is the name of the snippet.

PHX is available at

###Link Generation### There is a chunk named pdf-link.txt that includes an example how to create a link to the current document. The example looks like the following:

<a href="[*id*]?isPDF=true"Download">Download as PDF</a>

###Default Properties###

The snippet default properties are only needed, if you want to set TCPDF, htmlToPDF, or the document output to other paths, as defined by default. If you need to change this information, go the "Properties" tab on the htmlToPDF snippet and add the following parameters to the field "Default Properties" and afterwards insert your paths: &basePath=The base path for TCPDF and htmlToPDF;string; &htmlToPdfPath=The path to the classes of htmlToPDF;string; &tcpdfPath=The path to TCPDF;string; &outputPdfPath=The path, where the PDF documents are stored. You need to give read, delete, and create rights to that folder (777).;string;

###Parameters### The following parameters are available:

NameDescriptionPossible ValuesDefault
isPDFIs added to the document URI, to identify PDF calls.true
languageCodeThe PDF document language code.EN, DE,...EN
setDateFormatThe date format string for all dates.Y-m-d, d.m.YY-m-d
marginLeftThe left margin of the document.number in mm10
marginRightThe right margin of the document.number in mm10
marginTopThe top margin of the document.number in mm30
marginBottomThe top margin of the document.number in mm25
marginHeaderThe header margin of the document.number in mm5
marginFooterThe footer margin of the document.number in mm10
headerFontTypeThe header font type for standard headers.Fonthelvetica
headerFontSizeThe font size for standard headers.number16
headerFontBoldWhether the header font is bold, or not.Number 0 or 11
headerLogoThe logo for standard headers, the logo has to be in the
folder assets/lib/tcpdf/images/ to be found byTCPDF.
footerPositionFromBottomThe footer position from the bottom.number in mm15
footerFontTypeThe footer font type for standard footers.Fonthelvetica
footerFontItalicWhether the header font is italic, or not
for standard footers.
Number 0 or 11
footerFontSizeThe font size for standard footers.number8
contentFontTypeThe content font type for standard content.Fonttimes
contentFontSizeThe font size for standard content.number10
longTitleAboveContentWhether the documents long title should be in the
document above the content, or not, only
for standard content.
Number 0 or 11
stripCSSFromContentStrip in-line CSS, or not, only for standard content.Number 0 or 11
rewritePDFIf a PDF document exists, the document is not rewritten
every time, when the PDF document is requested. This
is a cache function for PDF documents.
Number 0 or 11
authorAuthor for PDF document properties.string
tvKeywordsA template variable for keywords for the PDF document properties.
Keywords are comma separated, you may reuse
keywords for tag clouds.
Template Variable
chunkHeaderChunk for customized headersChunk
chunkContentFooterChunk for customized text placed under the content. For example
for a link to the current document on the website inside the PDF
document. Only used with standard content.
chunkStyleA chunk for CSS styles in the PDF document.Chunk
chunkContentA chunk for individual arrangement of the
content in the document.
fontMonoSpacedThe Monospaced font.Fontcourier
imageScaleRatioThe scale ratio for images.number1.25
footerChunkThe footer chunk name.ChunkPage %1s / %2s
basePathThe base path for TCPDF and htmlToPDF.stringMODX_BASE_PATH
htmlToPdfPathThe path to the classes of htmlToPDF.stringassets/snippets/htmlToPDF/|
tcpdfPathThe path to TCPDF.stringassets/lib/tcpdf/
outputPdfPathThe path, where the PDF documents are stored. You
need to give read, delete, and create rights to that folder (777).
headerImageHeightSets the height for a logo in the header of the PDF document in mm.int20
printHeaderWhether to print a header, or not.Number 0 or 11
printFooterWhether to print a footer, or not.Number 0 or 11
lineColorString with 3 comma separated values as RGB.string0,0,0
You can’t perform that action at this time.