Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
78 lines (47 sloc) 1.89 KB
title type order
Working with PDFs
guide
5

The PdfModel

Whenever you’re dealing with a Printmaker-generated PDF, you’re actually working with a PdfModel object.

Output the PDF

These methods save the PDF to disk so that you can output it to the client.

PdfModel.output

Outputs the PDF directly to the browser, as if the current URL pointed directly to your generated PDF file.

(Streaming file contents to the client won't work if other page content has already been sent. Therefore, you should invoke this method before/above any other content is output to the template.)

{{ pdf.output }}

PdfModel.download

Streams the PDF as a download/attachment to the browser.

(Streaming file contents to the client won't work if other page content has already been sent. Therefore, you should invoke this method before/above any other content is output to the template.)

{{ pdf.output }}

PdfModel.url

Returns the URL of the generated PDF file.

{% set pdfUrl = printmaker.pdfFromTemplate('_myTemplate', someVars, someSettings).url %}

<a href="{{ pdfUrl }}">
   Download your PDF!
</a>

Email the PDF

PdfModel.email

Sends an email with the generated PDF attached.

  • filename Overrides the name of the file as it is attached to the email
  • settings Attributes to set on the EmailModel before it gets sent
  • variables The variables that will be available to to the email template (in addition to fileUrl)
{% set variables = {
   userName : currentUser.friendlyName
} %}
 
{% set settings = {
   toEmail: 'someone@website.com',
   subject: "Here's your PDF!",
   body: "Hi {{ userName }}! Your PDF is attached. You can also download it here: {{ fileUrl }}"
} %}
 
{% set pdf = printmaker.pdfFromTemplate('_pdf/_myTemplate', someVars, someSettings) %}
 
{% do pdf.email('YourPDF.pdf', settings, variables %}