Skip to content

Add page background color option to jsPDF constructor and API #3864

Open
@h-rushi

Description

@h-rushi

Summary

This enhancement should add support for setting a full-page background color in jsPDF, allowing users to create PDFs with colored backgrounds instead of the default white background.

Motivation

Currently, jsPDF only supports white page backgrounds. Many use cases require colored backgrounds for:

  • Branded documents with company colors
  • Dark mode PDF generation
  • Design templates with specific color schemes
  • Print materials requiring non-white backgrounds
  • Accessibility improvements with high-contrast backgrounds

Implementation Details

Constructor Option

Users should be able to set a page background color when creating a new jsPDF instance:

// Using hex color
const doc = new jsPDF({
  pageBackgroundColor: '#ffcccc'
});

// Using RGB array
const doc = new jsPDF({
  pageBackgroundColor: [255, 204, 204]
});

// Using named colors
const doc = new jsPDF({
  pageBackgroundColor: 'lightblue'
});

New API Methods

Two new methods should be added to the jsPDF API:

// Set background color for future pages
doc.setPageBackgroundColor('#ccffcc');

// Get current background color setting
const currentColor = doc.getPageBackgroundColor();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions