esono/pdf-renderer

There is no license information available for the latest version (8.0.3) of this package.

PDF Renderer client library

8.0.3 2026-01-28 12:44 UTC

README

Simple PDF renderer that renders HTML sent to it via POST request and responds with a PDF. This application uses puppeteer (headless chrome) internally - so the rendered result should be equivalent to using the 'print' functionality in your chrome.

Starting

Use the docker.esono.de/esono/pdf-renderer docker image in order to start using pdf-renderer in your project.

The following environment variables can be specified:

  • LISTEN: Sets the port (and optionally, host) to listen to (default: 80)
  • LOG_LEVEL influences the verbosity of the logs, can be one of the following:
    • emerg
    • alert
    • crit
    • error
    • warning
    • notice
    • info (default)
    • debug
- name: pdf-renderer
  image: 'docker.esono.de/esono/pdf-renderer:0.0.1'
  env:
    - name: LISTEN
      value: '8011'

Usage

The application has a single route:

POST /render/pdf

Assumes a HTML body and responds with a PDF version of that body. The following query string arguments exist:

  • width: The paper width, defaults to 210mm (A4)
  • height: The paper height, defaults to 297mm (A4)
  • waitForNetwork: Set to 1 in order to wait for all network requests to finish before rendering the page (see below).

Ideally, the posted HTML document should be self-contained without requiring any external resources. If your document contains external resources, they have to be absolute URLs including the host and you must specify waitForNetwork in order to wait for the all network requests to finish before rendering.

Warning: Using waitForNetwork will increase rendering time by a lot.

# Example request
$ curl \
  -X POST \
  -d '<h1>test</h1>' \
  'http://localhost:8011/render/pdf?width=100mm&height=100mm' \
  --output 'rendered.pdf'

PHP Library

The pdf renderer also contains a PHP Library / Symfony Bundle in order to make usage in PHP apps easier. To install it, install the esono/pdf-renderer composer package.

In order to start using the library in your chameleon / symfony project, first add the EsonoPdfRendererBundle to your list of bundles. After this, you will have to add the required configuration esono_pdf_renderer.base_url containing the URL of the pdf-renderer server - e.g. http://localhost:8011 if setup as shown in the example above.

Now you can either use autowiring to inject the PdfRendererInterface or manually inject the esono_pdf_renderer.pdf_renderer service.

Note: By default the library uses symfonies PSR HTTP Client implementation, which in turn requires a valid HTTP Library to be installed. You will likely be prompted to install nyholm/psr7 or any other library that provides psr/http-factory-implementation.

Alternatively, you can set esono_pdf_renderer.pdf_renderer to a service ID of a PSR7 compatible Http ClientInterface.