StaticloadInstantiate from raw wasm bytes, a URL/path, or a Response.
StaticloadConvenience loader for Node: instantiate from the gigapdf.wasm shipped
inside this package (resolved relative to the built module). In the browser,
pass a URL or bytes to load instead.
In Next.js output: "standalone", add the asset to outputFileTracingIncludes
for the consuming route so the .wasm is copied into the standalone bundle.
Copy host bytes into wasm memory; returns the pointer (caller frees).
Call a buffer-returning export (…, outLenPtr) -> dataPtr; copies + frees.
Like _json but distinguishes a null result (the export returned a
null pointer — e.g. an unrecognized container) from a present-but-empty JSON
payload ([] / {}). Returns null only for the null pointer; otherwise the
parsed JSON. Used where the Rust side is Option<…> and "nothing" and
"unrecognized" must stay distinct.
Like _str but distinguishes a null result (the export returned a
null pointer — e.g. an Option::None) from a present-but-empty string.
Returns null only for the null pointer; otherwise the decoded string.
Decode standard Base64 (RFC 4648) to bytes. Pure-JS table decode, so it
works identically in Node and the browser with no dependency (used to turn
the JSON dataBase64 of GigaPdfDoc.attachments back into bytes).
Open an encrypted PDF with a password. Returns null if the password is wrong.
Open a public-key (certificate) encrypted PDF (/Filter /Adobe.PubSec,
ISO 32000-1 §7.6.5) with a recipient's DER certificate + PKCS#1 RSA
privateKey. null if this key is not a recipient. Counterpart of
GigaPdfDoc.encryptForRecipients.
Inspect a PDF's encryption without decrypting it (no password needed):
whether it has an /Encrypt dictionary, plus its /P permission bitmask
and handler version/revision (0 when not encrypted).
Decode the eight access-permission flags from a /P permission bitmask
(ISO 32000-1 Table 22) into named booleans (true = the action is
granted). Reserved bits are ignored.
Read a PDF's access permissions without decrypting it (no password
needed). Returns the eight named flags decoded from the /Encrypt
dictionary's /P; an unencrypted document grants everything.
Pack eight access-permission flags into a signed 32-bit /P value
(ISO 32000-1 Table 22). Omitted flags default to granted, so an empty
object means "all allowed". Feed the result to GigaPdfDoc.saveEncrypted
via opts.permissions, or pass opts.flags directly.
Width of text set in standard Helvetica at size points (AFM metrics) —
place watermark/header text without embedding a font.
Office (DOCX/ODT/PPTX/XLSX/ODS) → PDF, auto-detected. Empty array if unrecognized.
Phase 1 for officeToPdf — the Google/system fonts an Office container
references but doesn't embed. Download each url (→ TTF) and supply the
bytes back to the host font cache so officeToPdf's styled runs lay out
with the right metrics. Faces the container embeds itself are de-obfuscated
and used automatically (not listed here). Returns null if the bytes are not
a recognized Office container, [] if it needs no host fonts.
Phase 2 for officeNeededFonts — render an Office container to PDF with
the host-fetched fonts embedded, so families the container references but
doesn't embed (reported by officeNeededFonts) lay out with the right
metrics (e.g. Carlito for a Calibri reference) instead of drifting onto the
bundled fallback. Faces the container embeds itself win on conflict, so an
empty fonts array yields exactly officeToPdf's output. Empty array
if the bytes are not a recognized Office container.
Image (PNG/JPEG/GIF/WebP/AVIF/TIFF) → one-page PDF, format auto-detected: the image is centred and scaled to fit on an A4 portrait page. PNG/JPEG embed directly; GIF/WebP/AVIF/TIFF are transcoded to PNG first — all in pure Rust/WASM, no third-party image library. Empty array if the bytes are not a recognized image. To combine many images into a single document, pipe each result through mergePdfs.
Merge several PDFs into one by appending their pages in order. Each input is
either raw bytes (every page) or a MergePart { pdf, pages? } that
selects 1-based page numbers (ISO 32000-1 §7.7.3) — so the two forms can be
mixed (e.g. [whole, { pdf: b, pages: [1, 3] }]). Returns an empty document
for an empty list, or — when the only input is a whole PDF (no pages) —
that input unchanged. Each subsequent part is appended onto the first via
GigaPdfDoc.appendPages; the merged bytes are returned and the working
document is closed.
Write a host-built grid (pages[rows][cells]) to an .xlsx workbook — one
sheet per page — with the engine's native spreadsheet writer (no
third-party library). Supply your own table reconstruction and still emit
Office output. sheetNames (index-aligned to grids) overrides the default
Page <n> titles; a missing/empty name falls back to the default.
gridsToOds is the OpenDocument (.ods) counterpart.
Write a host-built grid (pages[rows][cells]) to an .ods spreadsheet
(optional sheetNames, default Page <n>).
Read an .xlsx workbook back into per-sheet { name, rows } grids — the
inverse of gridsToXlsx / GigaPdfDoc.toXlsx. Cell text is
decoded from inline strings, shared strings (sharedStrings.xml) or plain
values; sheets come in workbook order. [] for a non-xlsx input.
Encode raw RGBA pixels (width*height*4 bytes, row-major,
non-premultiplied) to a PNG with the engine's native encoder — no
third-party image library. Returns an empty array if the buffer length
doesn't match width*height*4.
Resample raw RGBA pixels (sw×sh) to dw×dh with the engine's
native alpha-correct resampler (triangle kernel, footprint scaled for
down/up) — no third-party image library. Returns the resized RGBA
(dw*dh*4), or an empty array on a bad input.
Encode raw RGBA pixels to a baseline JPEG at quality (1–100) with the
engine's native encoder — no third-party image library. Alpha is composited
onto white. Empty array on a bad input.
Decode a baseline JPEG to { width, height, rgba }, or null on failure.
Decode a PNG to { width, height, rgba }, or null on failure.
Decode a GIF (first frame) to { width, height, rgba }, or null.
Encode raw RGBA pixels to a lossless WebP (VP8L) with the engine's native encoder — no third-party image library. Empty array on a bad input.
Decode a WebP to { width, height, rgba }, or null. Handles both
lossless (VP8L) and lossy (VP8 keyframe) WebP with the engine's
native decoder — no third-party image library. Extended/animated WebP
(VP8X) is not handled (returns null).
Decode a still AVIF (AV1 intra) to { width, height, rgba }, or null.
Pure-Rust AV1 decoder — no third-party library. Supports lossy + lossless
transforms, in-loop deblocking (AV1 §7.14) and CDEF (§7.15, including the
multi-strength cdef_bits > 0 path), screen-content palette mode
(§5.11.46-50), and both reduced_still_picture_header and the full
streaming sequence/frame headers — all validated bit-exact against dav1d.
Not yet covered: animated AVIF, film grain, loop restoration (§7.17), the
fully bit-exact directional top-right/bottom-left intra edge, and the
lossless WHT path at very-high quality (q ≤ 20).
Unpack a [w:u32 LE][h:u32 LE][rgba] decode buffer; null if empty.
Google Fonts CSS2 URL for a family/weight/italic (host fetches it).
Extract the trusted gstatic font URL from a Google Fonts CSS2 response.
Evaluate a JavaScript snippet with the built-in engine and return the
result value as a string (or Uncaught … / SyntaxError: …).
Run a document's inline <script>s and return the resulting HTML. The
htmlRender/htmlNeededFonts paths already do this automatically; use this
only when you want the post-script HTML on its own.
Phase 1 — the Google fonts the document references. Download each url
(→ TTF) and pass the bytes back to htmlRender for an identical render.
Phase 2 — render HTML + CSS to PDF, with the supplied fonts embedded (real Google fonts, real metrics → identical or nearest match). Block, inline and table layout with pagination. Page size and margin are in points (US-Letter portrait, 0.5in margins by default). JavaScript is not executed.
Resolve a named paper size — "A4", "a3-landscape", "letter", "legal",
"tabloid", "b5", … — to { w, h } in points (portrait unless the name
has a -landscape suffix). Returns null for an unknown name.
Phase 1 variant that also scans the running header/footer HTML, so the
Google fonts they reference are requested alongside the body's.
Optionalheader: stringOptionalfooter: stringPhase 2 with full page control: named/explicit size, per-side margins, and a
running header/footer painted in the page margins. {{page}} and {{pages}}
in the header/footer are replaced with the current / total page number.
const fonts = await fetchFonts(giga.htmlNeededFontsWith(html, header, footer));
const pdf = giga.htmlRenderWith(html, fonts, {
pageSize: "A4",
margin: { top: 72, bottom: 72, left: 54, right: 54 },
header: `<div style="text-align:center">My Report</div>`,
footer: `<div style="text-align:center">Page {{page}} / {{pages}}</div>`,
});
Phase 1 (unified) — every external resource the document needs the host to
fetch, in one list: fonts ({kind:"font",family,weight,italic,url}) and
external images ({kind:"image",url}). Run one fetch loop, then pass
fonts back as the fonts argument to GigaPdfEngine.htmlRenderWith
(download each url → TTF) and images via
HtmlRenderOptions.resources ({url, bytes}). data: image URIs are
inlined and never listed.
Optionalheader: stringOptionalfooter: stringLower an Office document (DOCX/XLSX/PPTX/ODT/ODS/ODP, auto-detected) into the
unified GigaDocument model. Returns null if the bytes aren't a
recognized Office container.
Lower an HTML string into the unified GigaDocument model.
Lower a Markdown string into the unified GigaDocument model (CommonMark-ish: headings, lists, GFM tables, fenced code, emphasis/links).
Lower a CSV file (UTF-8 bytes, RFC 4180, auto-detected ,/;/tab/|
delimiter) into the unified GigaDocument model as a single editable
table. Returns null if the bytes contain no parseable fields.
Lower an RTF string into the unified GigaDocument model. Routed
through the rich RTF parser, so run-level styling (bold/italic/underline/
strike, colour, size, family), tables, \pict images and \field
hyperlinks are recovered — the inverse of modelToRtf.
Lower a plain-text string into the unified GigaDocument model: one paragraph per line (blank lines kept as empty paragraphs).
Lower a raster image (PNG/JPEG/GIF/WebP, auto-detected) into the unified
GigaDocument model — a single full-page picture block sized to the
image's own aspect ratio, with the bytes interned in the model's resource
table. Returns null if the bytes aren't a recognized image.
Apply a batch of ModelOp edits to a model and return the edited model. Ops run in order; out-of-range addresses (and any op that can't be parsed) are silently skipped, so a partially-valid batch never throws.
Raise a GigaDocument model to an editable Word document (.docx).
Raise a model to an OpenDocument Spreadsheet (.ods).
Raise a model to an OpenDocument Presentation (.odp).
Raise a model to standalone HTML (decoded UTF-8 string).
Loaded engine module. Create documents with open / openEncrypted.