Skip to content

Support embedded-only fonts - avoid loading defaults during initialization #1647

@antaranyan

Description

@antaranyan

Bug Report

Description of the problem

PDFKit currently requires filesystem access to load default fonts during document initialization, even when later using only embedded fonts via registerFont(). This breaks in environments where system font paths are unavailable, e.g. compiled portable Deno executable in my case.

Code sample

// Fails - tries to load system fonts during initialization
const doc1 = new PDFDocument();

// Also fails - undefined still triggers default font loading
const doc2 = new PDFDocument({ font: undefined });

My current workaround is to initialize document with empty string to bypass default font loading, then register embedded fonts:

const doc = new PDFDocument({ font: "" }); // Skip system font loading
doc.registerFont('Courier', embeddedCourierData);
doc.font('Courier');

But would appreciate a cleaner solution.

Your environment

  • pdfkit version: 0.17.0
  • Node Deno version: 2.5.0
  • Browser version (if applicable): -
  • Operating System: Arch Linux

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