Paulsen PDF Generator

Include .pdf extension


Paulsen PDF Generator


Send a GET request to<url-encoded url>&filename=<filename.pdf>&last-modified=<last-modified string>


  • url - string - a url-encoded url from which to generate the PDF
  • filename - string - What to name the file. If the extension is not "pdf", ".pdf" will be added. Defaults to "file.pdf"
  • last-modified - string - A string representing when the page was last modified. Once a PDF is generated with a particular string, it gets cached until the cache lifetime (ttl) expires.
  • ttl - How many seconds the cached file should be valid for. Default: 1 week.
  • download - boolean - Whether or not to force a download of the generated file. Default false
  • reload-cache - boolean - If true, the system will re-generate the cached file

Custom Config

The system will check if /config/<domain-name>.json (in the PDF generator project, not the individual site) exists. Any values set there will override the defaults. Any wkhtmltopdf flags can be set in this JSON file.

Example Config

{ "margin-top": "20mm", "margin-bottom": "20mm", "header-center": "Centered Text for Header", "footer-center": "Centered Text for Footer" }

Custom CSS

To use an additional style sheet, add /config/<domain-name>.css. If the file exists, it will be used when rendering the page.

What it does

The system checks if the file /generate/cache/<domain-name>/<last-modified>/<filename> exists. If it does, it makes sure the file hasn't expired yet. If it's expired, it regenerates, then serves it. If it's still valid, it serves it. If the file does not exist, it creates the directory and file, then serves it.


It uses X server running as a daemon to render the page as a PDF. Its a fairly high overhead process, which is why it caches aggressively. If asked to render a very large page, it can take quite some time (several minutes). It can only generate one PDF at a time, but it can serve cached PDFs while generating. If it gets stopped up, you can SSH into the instance and run sudo killall wkhtmltopdf, which should stop the process, and allow new jobs to proceed as normal.

To Do

  • Clean up the code in /generate/index.php, probably make it into a class.