X Enterprises
fastify-xpdf

generateFromUrl

Navigate to a URL with Puppeteer and generate a PDF of the fully rendered page.

generateFromUrl

Navigate to a URL with Puppeteer's Chrome headless browser and capture the fully rendered page as a PDF. Waits for the network to settle before capturing (configurable via waitFor).

Signature

fastify.xPDF.generateFromUrl(
  url: string,
  options?: UrlPdfOptions,
): Promise<PdfResult>

interface UrlPdfOptions extends HtmlPdfOptions {
  waitFor?: string   // Puppeteer waitUntil value (default: "networkidle2")
  timeout?: number   // Navigation timeout in ms (default: 30000)
}

Params

NameTypeRequiredDescription
urlstringYesFully qualified URL to render — must be a valid URL
options.waitForstringNoPuppeteer waitUntil strategy: "networkidle0", "networkidle2", "load", "domcontentloaded" (default: "networkidle2")
options.timeoutnumberNoNavigation timeout in milliseconds (default: 30000)
options.formatstringNoPage format override
options.landscapebooleanNoLandscape orientation
options.marginobjectNoPage margins override
options.printBackgroundbooleanNoBackground colours/images
options.saveToStoragebooleanNoUpload result to xStorage
options.folderstringNoStorage folder override

Returns

Same PdfResult as generateFromHtml: { buffer, filename, size, storageKey?, url? }.

Throws

ErrorWhen
[xPDF] URL must be a non-empty stringurl is empty, null, or not a string
[xPDF] URL must be a valid URLMalformed URL string
[xPDF] Failed to initialize PDF browserPuppeteer/Chrome launch failure

Examples

Capture a public report page

fastify.post("/snapshots", async (request, reply) => {
  const { pageUrl, filename } = request.body;

  const { buffer } = await fastify.xPDF.generateFromUrl(pageUrl, {
    waitFor: "networkidle0",
    timeout: 60000,
    format: "A4",
    printBackground: true,
    filename,
  });

  return reply
    .header("Content-Type", "application/pdf")
    .header("Content-Disposition", `attachment; filename="${filename}"`)
    .send(buffer);
});

Archive a rendered dashboard page to storage

async function archiveDashboard(dashboardUrl) {
  const { url: storageUrl, storageKey } = await fastify.xPDF.generateFromUrl(
    dashboardUrl,
    {
      waitFor: "networkidle0",
      timeout: 45000,
      landscape: true,
      format: "A3",
      saveToStorage: true,
      folder: `archives/${new Date().toISOString().slice(0, 10)}`,
    },
  );

  return { storageUrl, storageKey };
}

See Also

AI Context

package: "@xenterprises/fastify-xpdf"
method: fastify.xPDF.generateFromUrl(url, options?)
use-when: Render a live URL to PDF using Puppeteer — navigates Chrome to the URL and captures the page
params: url (string), options (format, margin, printBackground, waitUntil, saveToStorage)
returns: { buffer, size } | { buffer, size, storageKey, url }
Copyright © 2026