Files
margin/src/export/exporters.ts
T
pj 7a2d7c6aff feat(fonts): honor selected fonts in PDF export
Interpolate the book's body and heading families into the Typst
preamble, title page, cover, and contents. Embed the needed bundled
fonts and load any chosen system fonts (via fontdb) into the Typst
engine so PDF preview and export match the on-screen fonts.
2026-06-22 14:27:51 -04:00

20 lines
749 B
TypeScript

import type { Book } from "../model/book";
import { bookToPdfInputs } from "./typst";
import { buildEpub } from "./epub";
import { compilePdf } from "../ipc";
import { saveBytes } from "../project";
const PDF = [{ name: "PDF", extensions: ["pdf"] }];
const EPUB = [{ name: "EPUB", extensions: ["epub"] }];
export async function exportPdf(book: Book): Promise<void> {
const { source, images, fonts } = bookToPdfInputs(book);
const bytes = await compilePdf(source, images, true, fonts);
await saveBytes(bytes, `${book.metadata.title || "Untitled"}.pdf`, PDF);
}
export async function exportEpub(book: Book): Promise<void> {
const bytes = await buildEpub(book);
await saveBytes(bytes, `${book.metadata.title || "Untitled"}.epub`, EPUB);
}