PDF

Overview

Below is a list of all the available drops on the <insert name here> object

Almost any page can be turned into a PDF simply by appending ".pdf" to the url.

By default this is equivalent to simply printing the page to a pdf but there are features to make it more adapted to the PDF format.

First the request drop has the "format" property. This can be used to hide or show parts of the page based on the format requested. Normally the format is "html", which means that request.format.html? is true; if the request is for a pdf request.format.pdf? will be true.

For instance to hide the shopping cart in pdf-files:

{% unless request.format.pdf? %}
  <a href="/shop">Varukorg</a>
{% endunless %}


Pages

Pages can have an entirely different template for pdf; simply name a template the same as the template for the page and append ".pdf" .
 

Products

Products require a specific pdf template, just select the "pdf" option for the shop template.
 

Lists

Most PDF files get their name from the url and so do list rows. However since list row may not have that column it can also be specifically set with the column "pdf_file_name".
 

Debug mode

By appending the parameter "debug-pdf", id est going to the url "https://your-pdf-page.pdf?debug-pdf", you can see the raw html used to generate the pdf.
 

More control

You can embed parameters in the html itself. You do this by adding a meta-elements. Available parameters are:

property example content  
orientation Landscape  
page_size A4, Letter  
pdf yellow-blue This is the file name the pdf will get.
page_height 100mm  
page_width 20cm  
<meta name="wm3:pdf" property="page_width" content="100mm">
<meta name="wm3:pdf" property="page_height" content="100mm">

 

The meta properties will override all other means of control. Right now that only applies to the file name.

Note that while meta-elements technically must be in the head, neither wm3 nor most browsers actually care.

Updated: 2020-08-20