@qrcommunication/gigapdf-lib — SDK API reference - v0.110.3
    Preparing search index...

    Class GigaPdfEngine

    Loaded engine module. Create documents with open / openEncrypted.

    Index

    Accessors

    Methods

    • Instantiate from raw wasm bytes, a URL/path, or a Response.

      Parameters

      • source: string | ArrayBuffer | Uint8Array<ArrayBufferLike> | Response

      Returns Promise<GigaPdfEngine>

    • Convenience 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.

      Returns Promise<GigaPdfEngine>

    • Copy host bytes into wasm memory; returns the pointer (caller frees).

      Parameters

      • bytes: Uint8Array

      Returns number

    • Parameters

      • ptr: number
      • len: number

      Returns void

    • Call a buffer-returning export (…, outLenPtr) -> dataPtr; copies + frees.

      Parameters

      • call: (outLenPtr: number) => number

      Returns Uint8Array

    • Parameters

      • call: (outLenPtr: number) => number

      Returns string

    • Type Parameters

      • T = unknown

      Parameters

      • call: (outLenPtr: number) => number

      Returns T

    • 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.

      Type Parameters

      • T = unknown

      Parameters

      • call: (outLenPtr: number) => number

      Returns T | null

    • 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.

      Parameters

      • call: (outLenPtr: number) => number

      Returns string | null

    • 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).

      Parameters

      • s: string

      Returns Uint8Array

    • Pass a string argument; runs fn(ptr, len) then frees.

      Type Parameters

      • T

      Parameters

      • s: string
      • fn: (ptr: number, len: number) => T

      Returns T

    • Pass an optional string; an absent/empty value runs fn(0, 0) (no alloc).

      Type Parameters

      • T

      Parameters

      • s: string | undefined
      • fn: (ptr: number, len: number) => T

      Returns T

    • Pass a bytes argument; runs fn(ptr, len) then frees.

      Type Parameters

      • T

      Parameters

      • bytes: Uint8Array
      • fn: (ptr: number, len: number) => T

      Returns T

    • Pass a u32[] argument (e.g. page numbers); runs fn(ptr, count) then frees.

      Type Parameters

      • T

      Parameters

      • values: number[]
      • fn: (ptr: number, count: number) => T

      Returns T

    • Pass a flat f64[] argument (e.g. ink x,y pairs); runs fn(ptr, count) then frees.

      Type Parameters

      • T

      Parameters

      • values: number[]
      • fn: (ptr: number, count: number) => T

      Returns T

    • Open an encrypted PDF with a password. Returns null if the password is wrong.

      Parameters

      • pdf: Uint8Array
      • password: string

      Returns GigaPdfDoc | null

    • 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.

      Parameters

      • pdf: Uint8Array
      • certificate: Uint8Array
      • privateKey: Uint8Array

      Returns GigaPdfDoc | null

    • 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).

      Parameters

      • pdf: Uint8Array

      Returns { encrypted: boolean; permissions: number; version: number; revision: number }

    • 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.

      Parameters

      • p: number

      Returns PdfPermissions

    • 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.

      Parameters

      • pdf: Uint8Array

      Returns PdfPermissions

    • 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.

      Parameters

      Returns number

    • Width of text set in standard Helvetica at size points (AFM metrics) — place watermark/header text without embedding a font.

      Parameters

      • size: number
      • text: string

      Returns number

    • Parameters

      • text: string

      Returns Uint8Array

    • Parameters

      • html: string

      Returns Uint8Array

    • Parameters

      • rtf: string

      Returns Uint8Array

    • Office (DOCX/ODT/PPTX/XLSX/ODS) → PDF, auto-detected. Empty array if unrecognized.

      Parameters

      • office: Uint8Array

      Returns Uint8Array

    • 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.

      Parameters

      • office: Uint8Array

      Returns HtmlFontRequest[] | null

    • 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.

      Parameters

      • office: Uint8Array
      • fonts: HtmlFont[] = []

      Returns Uint8Array

      const reqs = giga.officeNeededFonts(docx);            // phase 1: what to fetch
      const fonts = await Promise.all( // host fetches each url → TTF
      (reqs ?? []).map(async (r) => ({ ...r, ttf: await fetchTtf(r.url) }))
      );
      const pdf = giga.officeToPdfWith(docx, fonts); // phase 2: render with them
    • 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.

      Parameters

      • image: Uint8Array

      Returns Uint8Array

    • 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.

      Parameters

      • parts: (Uint8Array<ArrayBufferLike> | MergePart)[]

      Returns Uint8Array

    • 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.

      Parameters

      • grids: string[][][]
      • sheetNames: string[] = []

      Returns Uint8Array

    • Write a host-built grid (pages[rows][cells]) to an .ods spreadsheet (optional sheetNames, default Page <n>).

      Parameters

      • grids: string[][][]
      • sheetNames: string[] = []

      Returns Uint8Array

    • 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.

      Parameters

      • xlsx: Uint8Array

      Returns XlsxSheet[]

    • 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.

      Parameters

      • rgba: Uint8Array
      • width: number
      • height: number

      Returns Uint8Array

    • 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.

      Parameters

      • rgba: Uint8Array
      • sw: number
      • sh: number
      • dw: number
      • dh: number

      Returns Uint8Array

    • 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.

      Parameters

      • rgba: Uint8Array
      • width: number
      • height: number
      • quality: number = 82

      Returns Uint8Array

    • Decode a baseline JPEG to { width, height, rgba }, or null on failure.

      Parameters

      • jpeg: Uint8Array

      Returns DecodedImage | null

    • Decode a PNG to { width, height, rgba }, or null on failure.

      Parameters

      • png: Uint8Array

      Returns DecodedImage | null

    • Decode a GIF (first frame) to { width, height, rgba }, or null.

      Parameters

      • gif: Uint8Array

      Returns DecodedImage | 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.

      Parameters

      • rgba: Uint8Array
      • width: number
      • height: number

      Returns Uint8Array

    • 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).

      Parameters

      • webp: Uint8Array

      Returns DecodedImage | 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).

      Parameters

      • avif: Uint8Array

      Returns DecodedImage | null

    • Unpack a [w:u32 LE][h:u32 LE][rgba] decode buffer; null if empty.

      Parameters

      • bytes: Uint8Array
      • fn: (p: number, l: number, o: number) => number

      Returns DecodedImage | null

    • Google Fonts CSS2 URL for a family/weight/italic (host fetches it).

      Parameters

      • family: string
      • weight: number = 400
      • italic: boolean = false

      Returns string

    • Extract the trusted gstatic font URL from a Google Fonts CSS2 response.

      Parameters

      • css: string

      Returns string

    • Evaluate a JavaScript snippet with the built-in engine and return the result value as a string (or Uncaught … / SyntaxError: …).

      Parameters

      • src: string

      Returns string

    • 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.

      Parameters

      • html: string

      Returns string

    • Phase 1 — the Google fonts the document references. Download each url (→ TTF) and pass the bytes back to htmlRender for an identical render.

      Parameters

      • html: string

      Returns HtmlFontRequest[]

    • 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.

      Parameters

      • html: string
      • fonts: HtmlFont[] = []
      • pageWidth: number = 612
      • pageHeight: number = 792
      • margin: number = 36

      Returns Uint8Array

    • 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.

      Parameters

      • name: string

      Returns { w: number; h: number } | null

    • Phase 1 variant that also scans the running header/footer HTML, so the Google fonts they reference are requested alongside the body's.

      Parameters

      • html: string
      • Optionalheader: string
      • Optionalfooter: string

      Returns HtmlFontRequest[]

    • Phase 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>`,
      });

      Parameters

      Returns Uint8Array

    • 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.

      Parameters

      • html: string
      • Optionalheader: string
      • Optionalfooter: string

      Returns HtmlResourceNeed[]

    • Lower 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.

      Parameters

      • office: Uint8Array

      Returns GigaDocument | null

    • 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.

      Parameters

      • csv: Uint8Array

      Returns GigaDocument | null

    • 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.

      Parameters

      • rtf: string

      Returns GigaDocument

    • 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.

      Parameters

      • image: Uint8Array

      Returns GigaDocument | null