Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/barchart/aws-lambda-pdf-generator/llms.txt

Use this file to discover all available pages before exploring further.

The POST /print endpoint accepts a JSON request body with three top-level fields. Only html is required — the complete HTML document you want converted to a PDF. The optional source field attaches a label to Lambda log output for tracing, and the optional settings object is forwarded verbatim to Puppeteer’s page.pdf() method, giving you full control over paper size, margins, orientation, and more.

Schema

html
string
required
The complete HTML document to convert to a PDF. Must be a valid HTML string. Supports inline CSS, embedded JavaScript (though scripts do not execute during Puppeteer rendering by default), and standard HTML5 elements. Maximum size is bounded by API Gateway’s 10 MB request limit.
source
string
An optional identifier for the request. Used in Lambda log output to correlate log entries with a particular request origin. Has no effect on the generated PDF itself.Example values: "annual-report", "invoice-12345", "crude-oil-price-report".
settings
object
An options object passed directly to Puppeteer’s page.pdf() method. If omitted, Puppeteer defaults are used (Letter format, no background printing, 1× scale). See the Puppeteer settings Reference below for the most commonly used fields.

Full Example

The following request generates a styled A4 PDF with background colors, custom margins, and a source label for log correlation.
{
  "source": "quarterly-report",
  "html": "<html><head><style>body { font-family: Arial, sans-serif; margin: 40px; } h1 { color: #333; }</style></head><body><h1>Q4 2024 Report</h1><p>Revenue: $1.2M</p></body></html>",
  "settings": {
    "format": "A4",
    "landscape": false,
    "printBackground": true,
    "margin": {
      "top": "2cm",
      "bottom": "2cm",
      "left": "2cm",
      "right": "2cm"
    }
  }
}

Minimal Example

Only the required html field is needed. Puppeteer defaults (US Letter, portrait, no background) are applied when settings is omitted.
{
  "html": "<html><body><h1>Hello, PDF!</h1></body></html>"
}

Puppeteer settings Reference

The settings object is passed verbatim to Puppeteer’s page.pdf() call inside the Lambda handler. Every key-value pair you provide here maps directly to a Puppeteer PDF option. The table below covers the most commonly used properties.
PropertyTypeDescription
formatstringPaper format: Letter, Legal, Tabloid, Ledger, A0A6
widthstring | numberPage width, e.g. "210mm" (overrides format)
heightstring | numberPage height, e.g. "297mm" (overrides format)
landscapebooleanLandscape orientation (default: false)
printBackgroundbooleanPrint CSS background colors/images (default: false)
scalenumberScale factor 0.1–2 (default: 1)
margin.topstringTop margin, e.g. "1cm", "10px"
margin.bottomstringBottom margin
margin.leftstringLeft margin
margin.rightstringRight margin
displayHeaderFooterbooleanDisplay header/footer template (default: false)
headerTemplatestringHTML template for the print header
footerTemplatestringHTML template for the print footer
The full list of supported options is defined by Puppeteer’s PdfOptions. The service passes the settings object verbatim to page.pdf(), so all Puppeteer v22 options are supported.
Puppeteer waits for networkidle0 before printing — meaning it waits until there are no more than 0 active network connections for at least 500 ms. If your HTML references external resources such as images, fonts, or stylesheets, ensure those assets are reachable from the Lambda function’s network context. If they are not, either host them in a VPC-accessible location or inline them as base64 data URIs directly in your HTML.

Build docs developers (and LLMs) love