mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-02 19:17:03 +00:00
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.
20 lines
749 B
TypeScript
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);
|
|
}
|