The PDF service generates a PDF from a request containing HTML. It uses a headless Chrome browser to do this conversion, so it is highly reliable. Query string parameters can be used to control the rendering.
- POST /: A POST request to the root url of the service should have an HTML string as a body. The response is a binary PDF. Here are the query string options that are available:
- url: if this is provided, instead of using the request body as the source of HTML, the processor downloads and processes the HTML from the provided url on the public net.
- landscape=true|false: paper orientation, defaults to false.
- displayHeaderFooter=true|false: include header and footer, defaults to false.
- printBackground=true|false: print background graphics, defaults to false.
- scale=<number>: scaling of webpage rendering, defaults to 1.
- paperWidth=<number>: paper width in inches, defaults to 8.5.
- paperHeight=<number>: paper height in inches, defaults to 11.
- marginTop=<number>: top margin in inches, defaults to 1cm (0.4in).
- marginBottom=<number>: bottom margin in inches, defaults to 1cm (0.4in).
- marginLeft=<number>: left margin in inches, defaults to 1cm (0.4in).
- marginRight=<number>: right margin in inches, defaults to 1cm (0.4in).
- pageRanges=<page ranges>: which pages to print, e.g. 1-3, 4, 7-9. Defaults to empty string i.e. all pages.
- ignoreInvalidPageRanges=true|false: silently ignore parsed but invalid page ranges e.g. 9-7, default to false.
- headerTemplate=<html>: header HTML. The following class names when applied to an element result in a value being injected into the element:
date: formatted print date,
title: document title,
url: document location,
pageNumber: current page number,
totalPages: total pages in the document.
- footerTemplate=<html>: footer HTML. Class names as for headerTemplate.
- preferCSSPageSize=true|false: use page size as defined in CSS. Defaults to false.
Special configuration properties
pdfService has the standard configuration properties.
- Adapter name: There is currently only one option, chromeLambdaPdfConverter which runs headless Chromium in an AWS Lambda function to do the pdf conversion.
Common use patterns
There is a danger of the pdfService being hijacked by third parties if its full functionality is exposed to anonymous users. Generally a useful pattern especially in this case, is to have a pipeline which passes POSTed JSON through an HTML template before this being sent to the pdfService. A typical pipeline would be:
[ "/template/pdf-template", "/pdf" ]