mirror of
https://github.com/priyanshujain/margin.git
synced 2026-10-03 03:27:03 +00:00
feat(export): PDF and EPUB export with save dialog
This commit is contained in:
1 parent
da94acc0ec
commit
e424008d56
2 files changed
+38
No files matched your search
@@ -0,0 +1,19 @@
|
||||
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 } = bookToPdfInputs(book);
|
||||
const bytes = await compilePdf(source, images);
|
||||
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);
|
||||
}
|
||||
Reference in new issue
Block a user