Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
46 lines (30 sloc) 1.66 KB
title type order
Generating a PDF
guide
3

Basic Usage

Printmaker provides methods to create a new PDF file from HTML or template source.

These methods will return a PdfModel object, which allows you to edit, output, download, save, or send the generated PDF via your template.

You can supply HTML code directly using the pdfFromHtml method, or generate a PDF from a compiled template using the pdfFromTemplate method.

printmaker.pdfFromHtml

The pdfFromHtml() method accepts two parameters:

  • html (required) — the HTML which will be used to generate the PDF
  • settings (optional) — any custom settings for the PDF engine
{% set html %}
  <html>Howdy, world!</html>
{% endset %}
{% set settings = { orientation : 'portrait' } %}
 
{% set pdf = craft.printmaker.pdfFromHtml(html, settings) %}

printmaker.pdfFromTemplate

The pdfFromTemplate() method accepts three parameters:

  • a template (required) — the path/name of the Twig template, just like you'd use in an {% raw %}{% include %}{% endraw %} tag
  • variables (optional) — an object containing any variables you want to pass to the template for use in rendering its content
  • settings (optional) — any custom settings for the PDF engine
{% set vars = { title: 'Howdy, world!', foo: entry.fooField } %}
{% set settings = { orientation : 'portrait' } %}
 
{% set pdf = printmaker.pdfFromTemplate('_pdf/_myTemplate', vars, settings) %}