Skip to content

feat(cli): add export-pdf command for vector PDF export#63

Open
Xiaofei-fei wants to merge 1 commit into1weiho:mainfrom
Xiaofei-fei:feat/export-pdf
Open

feat(cli): add export-pdf command for vector PDF export#63
Xiaofei-fei wants to merge 1 commit into1weiho:mainfrom
Xiaofei-fei:feat/export-pdf

Conversation

@Xiaofei-fei
Copy link
Copy Markdown

Summary

Add open-slide export-pdf CLI command that exports slides to high-quality vector PDFs using Playwright.

Usage

# Export a specific slide
open-slide export-pdf my-deck

# Export all slides
open-slide export-pdf --all

# Export to a custom directory
open-slide export-pdf my-deck --out-dir ~/Desktop

How it works

  1. Builds the static site with open-slide build
  2. Starts a local SPA-aware static server
  3. For each slide page, navigates to the correct URL (?p=N)
  4. Clones the slide canvas into a clean DOM tree (removing editor chrome: sidebar, toolbar, etc.)
  5. Uses Chromium's print-to-PDF for true vector output (text is selectable/searchable)
  6. Merges multi-page slides into a single PDF with pdf-lib

Key technical detail

Chromium's page.pdf() print compositor has a separate rendering pipeline that ignores CSS changes made via page.evaluate(), page.addStyleTag(), or even page.emulateMedia(). Only replacing the DOM tree itself (using cloneNode + document.body replacement) reliably removes UI chrome from the PDF output.

Output

  • Format: PDF 1.7, vector (text selectable/searchable)
  • Page size: 1920×1080px per slide
  • Output directory: exports/ by default

Dependencies

Adds playwright and pdf-lib as dependencies to @open-slide/cli.

Add `open-slide export-pdf` CLI command that exports slides to
high-quality vector PDFs using Playwright.

Usage:
  open-slide export-pdf <slide-id>
  open-slide export-pdf --all
  open-slide export-pdf <slide-id> --out-dir ~/Desktop

How it works:
  1. Builds the static site with `open-slide build`
  2. Starts a local SPA-aware server
  3. For each slide page, navigates to the correct URL
  4. Clones the slide canvas into a clean DOM tree (removing
     editor chrome like sidebar and toolbar)
  5. Uses Chromium's print-to-PDF for true vector output
  6. Merges multi-page slides into a single PDF with pdf-lib

Key technique: Chromium's print compositor ignores CSS changes
made via page.evaluate(). Only replacing the DOM tree itself
(with cloneNode + body replacement) reliably removes UI chrome.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 5, 2026

@Xiaofei-fei is attempting to deploy a commit to the Yiwei Ho Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant