amici/craft-super-pdf

Create PDF files from html

5.0.0 2024-03-27 06:54 UTC

README

Creating PDF is easy and fast now with Super PDF. Plug, Twig and play. Super PDF is backed with DomPDF library and gives you full power to covert your twig templates into PDF. You can pass external CSS and HTML 4.0 attributes working with it. All the functionality DomPDF gives can be accessible easily in Super PDF.

Features

  • Handles most CSS 2.1 and a few CSS3 properties, including @import, @media & @page rules
  • Supports most presentational HTML 4.0 attributes
  • Supports external stylesheets, either local or through http/ftp (via fopen-wrappers)
  • Supports complex tables, including row & column spans, separate & collapsed border models, individual cell styling
  • Image support (gif, png (8, 24 and 32 bit with alpha channel), bmp & jpeg)
  • No dependencies on external PDF libraries, thanks to the R&OS PDF class
  • Inline PHP support
  • Basic SVG support

Requirements

  • PHP version 7.2.5 or higher
  • Craft CMS 3.6.0 or higher
  • DOM extension
  • MBString extension
  • php-font-lib
  • php-svg-lib

Note that some required dependencies may have further dependencies (notably php-svg-lib requires sabberworm/php-css-parser).

Installation

Open your terminal and go to your Craft project:

cd /path/to/project

Run this command to load the plugin:

composer require amici/craft-super-pdf

In the Control Panel, go to Settings → Plugins and click the “Install” button for Super PDF.

Usage

You can create PDF from HTML using this code:

{% set html %}
    <h1>This is a basic example</h1>
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod.</p>
{% endset %}

{% set settings = {
    filename: "My_PDF",
} %}

{{ craft.superpdf.html(html, settings) }}

You can create PDF from template using this code:

{% set settings = {
    filename: "My_PDF",
} %}

{% set vars = {
    entry : entry,
    data : data
} %}

{{ craft.superpdf.template("template/_pdf_template", settings, vars) }}

You can also create PDF and instead of preview it, show a URL to visit / download:

{% set settings = {
    filename: "My_PDF",
    type: 'object',
} %}

{% set vars = {
    entry : entry,
    data : data
} %}

{% set object = craft.superpdf.template("template/_pdf_template", settings, vars) %}

// Default echo object will return URL
{{ object }}

{{ object.url }}
{{ object.getUrl() }}

{{ object.path }}
{{ object.getPath() }}

{{ object.filename }}
{{ object.getFilename() }}

{{ object.kind }}
{{ object.size }}
{{ object.dateModified|date("m/d/Y H:i:s") }}

// Returns craft assets element. Only if PDF is stored in craft assets volumes instead of storage folder.
{{ object.asset }}
{{ object.getAsset() }}

Documentation

Visit the Super PDF page for all documentation, guides, pricing and developer resources.

Support

Get in touch with us via the Amici Infotech Support or by creating a Github issue