Skip to content

Create PDF on the fly with this flexible MODx snippet

Notifications You must be signed in to change notification settings

BobRay/MODx-htmlToPDF

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MODx-htmlToPDF

Stefanie Janine Stoelting

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.

The source is licensed under the GNU Lesser General Public License, version 2.1 as published at http://www.gnu.org/licenses/lgpl-2.1.html

This MODx snippet uses TCPDF, available at http://www.tcpdf.org/, to create the PDF Files from the content of a web document, published with MODx. TCPDF is part of the package.

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.

###Installation###

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

assets/lib/tcpdf/  

The snippet classes should be located at:

assets/snippets/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.

###Example Snippet Call###

Here is an example for a call to htmlToPDF:

 [!htmlToPDF?  
    &author=``Stefanie Janine Stoelting``  
    &tvKeywords=``documentTags``  
    &headerLogo=``logo.png``  
    &chunkContentFooter=``pdf-contentfooter``  
    &chunkStandardHeader=``pdf-header-text``  
    &chunkStyle=``pdf-style``  
 !]  

###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.
GIF, JPG, PNG
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.
Chunk
chunkStyleA chunk for CSS styles in the PDF document.Chunk
chunkContentA chunk for individual arrangement of the
content in the document.
Chunk
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).
stringassets/pdf/
headerImageHeightSets the height for a logo in the header of the PDF document in mm.int20

About

Create PDF on the fly with this flexible MODx snippet

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published