mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-10-04 02:33:47 +10:00
Work around more Forme 0.25 layout defects in the converter: row-reverse laid out as row, min and max widths ignored along a row, text dropping view children, empty text taking a line, overflowing optimal line breaks, a text in a splitting row wrecking later pages, page breaks on row items, four equal border sides, percentage corner radii, pictures under their shadow, and imported table rows. Rotation is left out while Forme misplaces rotated boxes; the stylesheet editor warns about it and about percentage padding. The page map rebuilds blocks Forme drops from its layout, the browser renderer rejects documents whose fonts can't load so callers fall back to the server PDF, and every render gets fresh font entries. Glalie's sidebar is one band at the combined tint. Tests are re-baselined where they encoded react-pdf metrics, and engine limits (list marker keep-together, RTL line order, characters above U+FFFF, percentage padding) are expected failures. The plan logs the migration in section 13.
30 lines
1.5 KiB
TypeScript
30 lines
1.5 KiB
TypeScript
import type { ResumeData } from "@reactive-resume/schema/resume/data";
|
|
import type { Template } from "@reactive-resume/schema/templates";
|
|
import type { ResumeRenderOptions } from "./context";
|
|
import type { PageMap } from "./page-map";
|
|
import type { SectionTitleResolver } from "./section-title";
|
|
import wasmUrl from "@formepdf/core/pkg-web/forme_bg.wasm?url";
|
|
import * as forme from "@formepdf/core/worker";
|
|
import { parseResumeData } from "@reactive-resume/schema/resume/data";
|
|
import { renderResume } from "./forme/render";
|
|
|
|
export type CreateResumePdfBlobOptions = {
|
|
data: ResumeData;
|
|
template?: Template | undefined;
|
|
renderOptions?: ResumeRenderOptions | undefined;
|
|
resolveSectionTitle?: SectionTitleResolver | undefined;
|
|
/** Receives the header, section and item boxes of this render (see `page-map.ts`). */
|
|
onPageMap?: ((pageMap: PageMap) => void) | undefined;
|
|
};
|
|
|
|
export const createResumePdfBlob = async ({ onPageMap, ...input }: CreateResumePdfBlobOptions): Promise<Blob> => {
|
|
const data = parseResumeData(input.data);
|
|
// The 6.5 MB engine downloads with the first PDF, not with the app.
|
|
await forme.init(wasmUrl);
|
|
const { pdf, pageMap, missingFonts } = await renderResume(forme, { ...input, data });
|
|
// Without its fonts the document would look wrong; callers fall back to the server's PDF instead.
|
|
if (missingFonts.length > 0) throw new Error(`Fonts could not be loaded: ${missingFonts.join(", ")}`);
|
|
onPageMap?.(pageMap);
|
|
return new Blob([pdf as Uint8Array<ArrayBuffer>], { type: "application/pdf" });
|
|
};
|