High-Level Recipe
createRecipe() loads the high-level, chainable API for creating and modifying
PDFs from bytes. Recipe runs in browser pages, module Workers, and Node.js, uses
a top-left coordinate origin, and returns an owned Uint8Array from endPDF().
import { createRecipe } from "@muhammara/wasm";
var Recipe = await createRecipe();
var pdfBytes = new Recipe()
.createPage("A4")
.text("Hello from Recipe", 72, 72, { size: 24 })
.endPage()
.endPDF();
var pdfBlob = new Blob([pdfBytes], { type: "application/pdf" });
Recipe bundles Roboto Regular, so this example needs no font upload. Registered fonts, images, and source PDFs are also byte-backed; filesystem paths and Node streams are not accepted.
Named Option Values
Recipe string options have named values on the Recipe class, for example
Recipe.TextWrap.ELLIPSIS, Recipe.AnnotFlag.PRINT, and Recipe.PageSize.A4.
The plain strings stay accepted. In TypeScript, each set has a same-named
type for its values, for example Recipe.TextWrap or Recipe.AnnotFlag. Native and Wasm share these sets with the same
names and members: TextWrap, TextAlign, HorizontalAlign, VerticalAlign, TableRowNth,
LineCap, LineJoin, ArrowAt, ArrowType, TriangleTrait,
TrianglePosition, PageLayout, PageSize, FontStyle, Permission,
Coordinate, Colorspace, AnnotSubtype, AnnotFlag, AnnotIcon, and
ChromaCommand. Wasm also has Recipe.StructureFormat for structure(); native's
Recipe.Source has no Wasm counterpart because Wasm Recipe never writes to a
path.
Topics
- Create PDFs
- Pages And Positioning
- Text And Fonts
- Colors, Shapes, And Vectors
- Compose PDFs
- Modify And Inspect PDFs
- Metadata And Custom Data
- Recipe API Invariants
- Encrypt PDFs
Task-Oriented Guides
- Add Review Annotations
- Create Multi-Page Tables
- Create A Pie Chart
- Flow Text Into Columns
- Watermark Every Page
- Add Clickable URL Links
- Add Content To Rotated Pages
- Change PDF Passwords
- Place And Transform Images
Use the generated API reference for complete method and option signatures. Review Differences And Restrictions before porting native Recipe code.