Add-on, ExpressionEngine, PDF

PDF Press

Generate PDFs directly from your EE templates! Powered by mPDF.

Buy Now

PREREQUISITES

PHP 7.3+ DOMDocument extension MBString extension XML extension GD ExpressionEngine 6.0+ Opcache and IMagick or GMagick (recommended)

INSTALLATION

  1. Copy entire pdf_press folder to your system/user/addons folder.
  2. Copy entire themes/pdf_press folder to your themes folder, so that you have /themes/users/pdf_press
  3. On your EE backend, navigate to Developer > Addons (yoursite.com/admin.php?/cp/addons).
  4. Scroll to Third Party Add-Ons.
  5. Find PDF Press and click Install.
  6. Add your settings, and enjoy!

Upgrading From Previous Versions

PDF Press V5 now requires a themes folder. If you are upgrading, ensure you follow step 2 in the installation instructions.

USAGE

PDF Press has two tags, each will generate a PDF from an ExpressionEngine template.

save_to_pdf: Generate PDF

{exp:pdf_press:save_to_pdf}

The save_to_pdf tag generates a link to download the template as a PDF, it contains the following parameters:

  • path: Accepts an ExpressionEngine template path in the form template_group/template (ex. site/pdf), if no path is given then the current page will be used.

  • filename: Sets the filename for the downloaded PDF. Default: filename.pdf

  • size: sets the paper size for the PDF (ex. letter, legal, a5, etc). Paper sizes are listed below.

  • orientation: sets the orientation of the page, either portrait (default) or landscape. Default: portrait.

  • attachment: Automatically downloads the generated PDF. If the attachment parameter is set to 0 the PDF will be opened in the browser. Default: 1

  • key: Optional setting preset shortcode. See Settings Presets for more information.

  • default_font: Default font family to use in your PDF. This must match your font name inside of your add-on settings.

Example:

<a href="{exp:pdf_press:save_to_pdf path='site/projects' attachment='0' filename='projects.pdf'}">Download Project Case Studies</a>

This will create a link to open a PDF titled "projects.pdf" in the browser using the site/projects template

parse_pdf: Parse Inline Template to PDF

{exp:pdf_press:parse_pdf}

Sometimes you'll want to create a PDF with a member only or logged in page. For this you want to use parse_pdf:

{exp:pdf_press:parse_pdf}
    <html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>Parse Test</title>
    </head>
    <body>
        {if logged_in}
            {exp:channel:entries channel="Projects"}
                <p><strong>{title}</strong></p>
            {/exp:channel:entries}
        {if:else}
            <p>Not logged in</p>
        {/if}
    </body>
    </html>
{/exp:pdf_press:parse_pdf}

As you can guess, this tag, instead of creating a link to download/open a PDF, will create a PDF using whatever HTML & EE tags that are inside the parse_pdf tag-pair. It has all of the same parameters as save_to_pdf (except for path)

Note: Remember to put the parse_pdf tag before and after the HTML tag (and DOCTYPE) otherwise PDF Press won't render your complete page)

SETTINGS

Presets are a great way to save time, they allow you to set all of the options passed as parameters in the save_to_pdf & parse_pdf tags in the Control Panel. You can then re-use those settings in your template by just passing the short code into the "key" parameter.

{exp:save_to_pdf key="product_settings"}

Presets also let you securely set a variety of security settings for your PDFs. You can enable encryption, set a owner password, user password and then control if users can save, print, or modify PDFs.

You can access the Setting Presets by going to Add-Ons > Modules > PDF Press > Setting Presets

FONT SUPPORT

Custom fonts are supported inside of PDF press. Fonts must be of the TrueType format (ttf), and must be placed in themes/user/pdf_press/fonts.

Adding a Font

Add the font in your settings. Include a name for that font that will refer to your font when you use it in your CSS. Please note, this name should be lowercase and include only dashes (no spaces or punctuation); the settings manager will do this for you if you forget.

Include the names of a regular, bold, and italic font TTF file that is included in your themes/users/pdf_press/fonts folder.

Using a Font

Fonts are applied to your text in a few different ways:

CSS

All CSS in PDF Press is inlined as its read, so you can apply a font as you would on HTML. Ensure the font-family on your element is applied with the same name that appears in the fonts settings.

Default Font

If you are applying the font across the entirety of your document, you can use the default_font parameter as indicated above. Ensure the font-family on your element is applied with the same name that appears in the fonts settings.

PARAMETERS

PDF Press uses mPDF as it's engine, and accepts all parameters. See [https://mpdf.github.io/reference/mpdf-variables/overview.html](the mPDF documentation) for more info. All additional mpdf parameters can be added to your EE tag as such:

Pagination

Page Numbering

Fonts, Languages and Character sets

Configuration

Debugging

PDF/A1-b, PDF/X-1a Colorspaces

Annotations

Bookmarks (Outlines)

CSS & Styles

Page Headers & Footers

Tables

Images

Text Spacing & Justification

Hyphenation

Columns

Lists

Watermarks

Bookmarks

SUPPORT

For any issues, please reach out to mailto:[email protected]