@node-media-library/pdf
v1.0.0
Published
pdftoppm-backed ImageGenerator for rasterizing PDF originals in @node-media-library/core.
Maintainers
Readme
@node-media-library/pdf
PDF-backed ImageGenerator using poppler's pdftoppm for rendering pages as PNG, then applying conversions through the sharp pipeline.
Installation
pnpm add @node-media-library/pdf sharpsharp is a required optional peer. This package rasterizes into core's
sharpImageGenerator(), so sharp must be installed even though it is declared optional. It is marked optional only because core declares it that way.
System Requirements
Requires the pdftoppm binary from the poppler utilities:
- macOS:
brew install poppler - Linux (Debian/Ubuntu):
apt install poppler-utils - Linux (Fedora/RHEL):
dnf install poppler-utils
Usage
Append the PDF generator to your imageGenerators array alongside sharpImageGenerator:
import { createMediaLibrary, sharpImageGenerator } from '@node-media-library/core'
import { pdfImageGenerator } from '@node-media-library/pdf'
createMediaLibrary({
// ...
imageGenerators: [sharpImageGenerator(), pdfImageGenerator()],
})Configuration
pdfImageGenerator(options?)
Options
pdftoppmPath(string): Path to thepdftoppmbinary. Default:'pdftoppm'(assumes it's on PATH)dpi(number): Render resolution in DPI. Default:150
Example
pdfImageGenerator({
pdftoppmPath: '/usr/local/bin/pdftoppm',
dpi: 300,
})Selecting Pages
Use conversion().pdfPageNumber(n) to select which page to render (default is page 1):
import { collection, conversion } from '@node-media-library/core'
collection().conversions({
// Render page 2 at 800px wide
cover: conversion().pdfPageNumber(2).width(800),
})conversions() takes the builders themselves — don't call .toDefinition(), which is applied for you.
Testing
Tests include binary-gated suites that skip when pdftoppm is not available. Pure tests (those not requiring the binary) always run:
pnpm --filter @node-media-library/pdf test- ✓ Pure tests (MIME type support) run without pdftoppm
- ⊘ Binary-gated tests skip if pdftoppm not found
- Install poppler to run all tests
