Skip to content

Configuration Guide

All PDF generation methods accept a PDFConfig object. Config is deep-merged from multiple levels — see Configuration Priority.

Type Reference

typescript
interface PDFConfig {
  pageSize?: "A4" | "A3" | "LETTER" | "LEGAL" | { width: number; height: number };
  margins?: {
    top?: number;
    right?: number;
    bottom?: number;
    left?: number;
  };
  filename?: string;
  scale?: number;
  metadata?: {
    title?: string;
    author?: string;
    subject?: string;
    keywords?: string[];
    creator?: string;
  };
  styles?: {
    backgroundColor?: string;
    defaultFontSize?: number;
    defaultFontFamily?: string;
    defaultTextColor?: string;
    customCSS?: string;
  };
  container?: {
    className?: string;
    style?: React.CSSProperties;
  };
  header?: {
    text: string | string[];
    fontSize?: number;
    fontColor?: string;
    marginTop?: number;
    marginLeft?: number;
    marginRight?: number;
    align?: "left" | "center" | "right";
  };
  footer?: {
    text: string | string[];
    fontSize?: number;
    fontColor?: string;
    marginBottom?: number;
    marginLeft?: number;
    marginRight?: number;
    align?: "left" | "center" | "right";
  };
  watermark?: {
    text: string;
    fontSize?: number;
    color?: string;
    opacity?: number;
    angle?: number;
  };
}

Page Configuration

OptionTypeDefaultDescription
pageSize"A4" | "A3" | "LETTER" | "LEGAL" | { width: number, height: number }"A4"Page size. Custom sizes in mm.
margins{ top?, right?, bottom?, left? } (numbers in mm)20 eachPage margins
filenamestring"document.pdf"Downloaded file name
scalenumber2Canvas scale — higher = sharper, larger file
tsx
const config = {
  pageSize: "A4",
  margins: { top: 20, right: 20, bottom: 20, left: 20 },
  filename: "report.pdf",
  scale: 2,
};

Styles

Applied to the rendered content before capture. All fields are optional with no defaults (except backgroundColor which defaults to "#ffffff").

OptionTypeDefaultDescription
styles.backgroundColorstring"#ffffff"Background color of the PDF
styles.defaultFontSizenumberFont size in px applied to root element
styles.defaultFontFamilystringFont family applied to root element
styles.defaultTextColorstringText color applied to root element
styles.customCSSstringInjected as a <style> tag into the captured content
tsx
const config = {
  styles: {
    backgroundColor: "#ffffff",
    defaultFontSize: 14,
    defaultFontFamily: "Georgia, serif",
    defaultTextColor: "#222222",
    customCSS: `
      .highlight { background: #fff3cd; padding: 4px 8px; border-radius: 4px; }
    `,
  },
};

Container

Controls the wrapper element around your content. Useful for fixing a width so the PDF layout is consistent regardless of the browser window.

OptionTypeDescription
container.styleReact.CSSPropertiesInline styles on the wrapper div
container.classNamestringCSS class added to the wrapper div
tsx
const config = {
  container: {
    style: {
      width: "800px",
      margin: "0 auto",
    },
  },
};

Drawn as text above content on every page. Only rendered when header.text is set.

OptionTypeDefaultDescription
header.textstring | string[]Header text. Supports {pageNumber} and {totalPages}. Pass an array for multi-line.
header.fontSizenumber12Font size in pt
header.fontColorstring"#000000"Hex color string
header.marginTopnumberpage margins.topDistance from top of page in mm
header.marginLeftnumberpage margins.leftLeft offset for left/right align
header.marginRightnumberpage margins.rightRight offset for right align
header.align"left" | "center" | "right""center"Text alignment
tsx
const config = {
  header: {
    text: "Acme Corp — Quarterly Report",
    fontSize: 10,
    fontColor: "#666666",
    marginTop: 10,
    align: "center",
  },
};

Same as header but positioned at the bottom. Only rendered when footer.text is set.

OptionTypeDefaultDescription
footer.textstring | string[]Footer text. Supports {pageNumber} and {totalPages}.
footer.fontSizenumber12Font size in pt
footer.fontColorstring"#000000"Hex color string
footer.marginBottomnumberpage margins.bottomDistance from bottom of page in mm
footer.marginLeftnumberpage margins.leftLeft offset for left/right align
footer.marginRightnumberpage margins.rightRight offset for right align
footer.align"left" | "center" | "right""center"Text alignment
tsx
const config = {
  footer: {
    text: "Page {pageNumber} of {totalPages}",
    fontSize: 10,
    marginBottom: 10,
    align: "center",
  },
};

Page Variables

Use {pageNumber} and {totalPages} anywhere in header.text or footer.text:

tsx
footer: { text: "Page {pageNumber} of {totalPages} — Confidential" }
// → "Page 1 of 4 — Confidential"

Pass an array for multi-line text:

tsx
header: { text: ["Company Name", "Department Report"] }

Watermark

Text stamped diagonally across every page. Only rendered when watermark.text is set.

OptionTypeDefaultDescription
watermark.textstringWatermark text (required)
watermark.fontSizenumber20Font size in pt
watermark.colorstring"#888888"Hex color string
watermark.opacitynumber0.3Opacity from 0 (invisible) to 1 (solid)
watermark.anglenumber-45Rotation in degrees
tsx
const config = {
  watermark: {
    text: "CONFIDENTIAL",
    fontSize: 60,
    color: "#FF0000",
    opacity: 0.15,
    angle: -45,
  },
};

Metadata

Embedded in the PDF file properties (not visible in the document).

tsx
const config = {
  metadata: {
    title: "Q1 Report",
    author: "Finance Team",
    subject: "Quarterly financial summary",
    keywords: ["finance", "Q1", "2024"],
    creator: "EasyPdf",
  },
};

Complete Example

tsx
const config: PDFConfig = {
  pageSize: "A4",
  margins: { top: 25, right: 20, bottom: 25, left: 20 },
  filename: "report.pdf",
  scale: 2,
  styles: {
    backgroundColor: "#ffffff",
    defaultFontSize: 13,
    defaultFontFamily: "Arial, sans-serif",
    defaultTextColor: "#333333",
  },
  container: {
    style: { width: "800px", margin: "0 auto" },
  },
  header: {
    text: "ACME Corp — Internal Report",
    fontSize: 10,
    fontColor: "#999999",
    marginTop: 10,
    align: "right",
  },
  footer: {
    text: "Page {pageNumber} of {totalPages}",
    fontSize: 10,
    marginBottom: 10,
    align: "center",
  },
  watermark: {
    text: "CONFIDENTIAL",
    fontSize: 60,
    color: "#FF0000",
    opacity: 0.12,
    angle: -45,
  },
  metadata: {
    title: "Internal Report",
    author: "ACME Corp",
  },
};

Released under the MIT License.