### Install ReamKit Source: https://reamkit.dev/playground Use this command to install the ReamKit package via npm. ```bash npm i reamkit ``` -------------------------------- ### get(id) Source: https://reamkit.dev/api/index/classes/resourcestore Retrieves the binary data associated with a specific ResourceId. ```APIDOC ## get(id) ### Description Look up the bytes for a given id. Returns undefined if the id is not present in the store. ### Parameters - **id** (ResourceId) - The identifier to look up. ### Returns - **Uint8Array | undefined** - The binary data or undefined if not found. ``` -------------------------------- ### new ResourceStore() Source: https://reamkit.dev/api/index/classes/resourcestore Creates a new instance of the ResourceStore. ```APIDOC ## new ResourceStore() ### Description Initializes a new instance of the ResourceStore for managing binary payloads. ### Returns - **ResourceStore** - A new instance of the store. ``` -------------------------------- ### localFontProvider() Source: https://reamkit.dev/api/index/functions/localfontprovider Initializes a FontProvider that attempts to access system fonts via the Local Font Access API. ```APIDOC ## localFontProvider() ### Description Accesses system fonts via the Local Font Access API (Chromium 103+). This function is opt-in and returns a 'none' state if the API is unavailable, the font is not installed, or the font's OS/2 fsType restricts embedding. ### Signature `localFontProvider(): FontProvider` ### Returns - **FontProvider** - An instance of the font provider configured for local system font access. ``` -------------------------------- ### Configure Renderer Parity Source: https://reamkit.dev/guides/examples Use layoutProfile to match line-height models and kerning behavior of specific external renderers like LibreOffice or Microsoft Word. ```javascript const pdf = await doc.convert('pdf', { fonts, layoutProfile: 'libreoffice' }); // 'word' targets Microsoft Word; 'ream' (the default) is Ream's own typesetter. ``` -------------------------------- ### fetchFontSet(options?) Source: https://reamkit.dev/api/index/functions/fetchfontset Downloads a full variant set for the open family that best matches the requested name. ```APIDOC ## fetchFontSet(options?) ### Description Download a full variant set (regular required; bold/italic/bold-italic best-effort) for the open family that best matches the requested name. ### Signature `fetchFontSet(options?: FetchFontSetOptions): Promise` ### Parameters - **options** (FetchFontSetOptions) - Optional - The family to substitute and an optional fetch override. ### Returns - **Promise** - The downloaded font bytes per variant. ### Throws - **Error** - Thrown when the required regular face cannot be downloaded. ``` -------------------------------- ### remoteFontProvider(options?) Source: https://reamkit.dev/api/index/functions/remotefontprovider Creates a FontProvider that fetches metric-compatible font substitutes from a CDN. ```APIDOC ## remoteFontProvider ### Description Creates a `FontProvider` that provides Open CDN substitutes (Arimo / Tinos / Cousine / Carlito / Caladea) which are metric-compatible with LibreOffice fonts. This provider always returns a result, which the provider chain interprets as a substitution. ### Signature `remoteFontProvider(options?: { fetch?: FetchLike }): FontProvider` ### Parameters - **options** (object) - Optional - Configuration options for the font provider. - **fetch** (FetchLike) - Optional - A custom fetch implementation to use for retrieving font data. ### Returns - **FontProvider** - An instance of a FontProvider configured to use remote CDN substitutes. ``` -------------------------------- ### Convert file input to PDF preview in browser Source: https://reamkit.dev/guides/examples Reads a file from an input element, converts it to PDF, and opens it in a new window. ```typescript import { Ream } from 'reamkit'; input.addEventListener('change', async () => { const bytes = new Uint8Array(await input.files![0].arrayBuffer()); const pdf = await Ream.parse(bytes).convert('pdf'); window.open(URL.createObjectURL(new Blob([pdf], { type: 'application/pdf' }))); }); ``` -------------------------------- ### convert(bytes, options?) Source: https://reamkit.dev/api/index/interfaces/converter Reads the provided bytes and converts them to the requested target format, defaulting to 'pdf'. ```APIDOC ## convert(bytes, options?) ### Description Reads the provided bytes and converts them to the requested target format, defaulting to 'pdf'. ### Parameters - **bytes** (Uint8Array) - Required - The input data to convert. - **options** (ConvertOptions) - Optional - Configuration options for the conversion process. ### Returns - **Promise** - A promise that resolves to the conversion result. ``` -------------------------------- ### createConverter(opts?) Source: https://reamkit.dev/api/index/functions/createconverter Builds a Converter instance over a reader registry. This function is the primary entry point for setting up document conversion capabilities. ```APIDOC ## createConverter ### Description Builds a Converter over a reader registry. The async boundary (font fetching) lives here; readers and writers stay synchronous. ### Signature `createConverter(opts?: CreateConverterOptions): Converter` ### Parameters - **opts** (CreateConverterOptions) - Optional - Optional reader-registry override. ### Returns - **Converter** - A converter exposing `readers`, `detect` and `convert`. ``` -------------------------------- ### Read and convert PDF documents Source: https://reamkit.dev/guides/examples Shows how to parse a PDF and convert it into HTML or DOCX formats, including how to retrieve conversion loss reports. ```javascript import { Ream } from 'reamkit'; const doc = Ream.parse(pdfBytes); // doc.format === 'pdf' const html = await doc.convert('html'); // the PDF's text as flowed HTML const docx = await doc.convert('docx'); // …or an editable Word document const { bytes, losses } = await doc.convertWithReport('html'); // losses note the untagged-heuristic degradation and any unread vector art. ``` -------------------------------- ### Parse and convert documents with Ream Source: https://reamkit.dev/api/index/classes/ream Demonstrates the lifecycle of parsing raw bytes into a Ream instance and performing multiple conversions using the same interlayer. ```typescript 1 const doc = Ream.parse(bytes); // sniff → reader → FlowDoc 2 const pdf = await doc.convert('pdf', { fonts }); 3 const svg = await doc.convert('svg', { fonts }); ``` -------------------------------- ### readXlsx(xlsx, options?) Source: https://reamkit.dev/api/index/functions/readxlsx Reads a .xlsx file (as Uint8Array) and projects it into a FlowDoc. ```APIDOC ## readXlsx(xlsx, options?) ### Description Read a .xlsx and project it to a FlowDoc in one step. The parsing is lossless, while the projection applies defense-in-depth caps to grid size, text budget, and sparkline ranges. ### Parameters - **xlsx** (Uint8Array) - Required - The .xlsx (OPC ZIP) bytes. - **options** (ProjectSheetOptions) - Optional - Projection knobs (the W9 reference date). Defaults to {}. ### Returns - **ReadResult** - The flow document plus any clipping reports from the projection process. ``` -------------------------------- ### createHyphenator(patterns, options?) Source: https://reamkit.dev/api/index/functions/createhyphenator Builds a Liang pattern-based Hyphenator from a provided list of patterns and optional configuration. ```APIDOC ## createHyphenator(patterns, options?) ### Description Builds a Liang pattern-based Hyphenator from a pattern list. This function returns a Hyphenator instance configured with the provided TeX-style patterns. ### Parameters - **patterns** (readonly string[]) - Required - The TeX-style hyphenation patterns (e.g., "hy3ph"). - **options** (HyphenatorOptions) - Optional - Left/right minimums and explicit exceptions. Defaults to {}. ### Returns - **Hyphenator** - The initialized hyphenator instance. ``` -------------------------------- ### pxToPt(px) Source: https://reamkit.dev/api/index/functions/pxtopt Converts a value in CSS reference pixels to points. ```APIDOC ## pxToPt ### Description Converts CSS reference pixels to points. The conversion follows the standard: 96 px = 1 inch = 72 pt. ### Signature `pxToPt(px: number): Pt` ### Parameters - **px** (number) - The value in CSS reference pixels to convert. ### Returns - **Pt** - The converted value in points. ``` -------------------------------- ### size Source: https://reamkit.dev/api/index/classes/resourcestore Returns the number of distinct resources stored. ```APIDOC ## size ### Description Gets the number of distinct resources currently stored. ### Returns - **number** - The count of stored resources. ``` -------------------------------- ### halfPtToPt(halfPt) Source: https://reamkit.dev/api/index/functions/halfpttopt Converts a value from half-points to points. Note that 2 half-points equal 1 point. ```APIDOC ## halfPtToPt ### Description Converts OOXML font size units (half-points) to standard points (Pt). ### Signature `halfPtToPt(halfPt: number): Pt` ### Parameters - **halfPt** (number) - The font size value in half-points (e.g., 2 half-points = 1 pt). ### Returns - **Pt** - The converted font size in points. ``` -------------------------------- ### Access document properties and conversion options Source: https://reamkit.dev/guides/getting-started Inspect the parsed document object or perform conversions with reporting and strict error handling. ```javascript const doc = Ream.parse(bytes); doc.format; // 'docx' | 'xlsx' | 'pptx' | 'pdf' doc.flow; // the parsed interlayer tree (paragraphs, tables, images, …) doc.losses; // anything dropped/degraded while reading const { bytes: out, losses } = await doc.convertWithReport('pdf', { fonts }); await doc.convert('pdf', { fonts, strict: true }); // throw on the first loss ``` -------------------------------- ### Convert files in Node.js Source: https://reamkit.dev/guides/examples Reads a local DOCX file and writes the converted PDF to the filesystem. ```typescript import { readFileSync, writeFileSync } from 'node:fs'; import { Ream } from 'reamkit'; const doc = Ream.parse(new Uint8Array(readFileSync('report.docx'))); writeFileSync('report.pdf', await doc.convert('pdf')); ``` -------------------------------- ### writeSvg(laid, opts?) Source: https://reamkit.dev/api/index/functions/writesvg Renders a LaidOutDocument to a single SVG preview. Pages are stacked vertically with a configurable gap. ```APIDOC ## writeSvg(laid, opts?) ### Description Render a LaidOutDocument to a single SVG preview. PageItem coordinates are emitted verbatim as they align with the SVG coordinate system. Pages are stacked vertically, separated by a configurable gap, and rendered on white outlined rectangles. ### Parameters - **laid** (LaidOutDocument) - Required - The laid-out, paginated document from the layout engine. - **opts** (SvgWriteOptions) - Optional - Configuration object for options such as page-gap override. Defaults to {}. ### Returns - **WriteResult** - The encoded SVG bytes plus the recorded Loss list. ``` -------------------------------- ### Normalize and edit DOCX files Source: https://reamkit.dev/guides/examples Use convert('docx') to generate a fresh, valid DOCX file. Note that this process is semantic and does not preserve original markup verbatim. ```javascript import { Ream } from 'reamkit'; const doc = Ream.parse(bytes); // a .docx (xlsx has no docx writer) const out = await doc.convert('docx'); // `out` is a fresh, valid .docx — hand it to a download, an upload, or re-parse it. ``` -------------------------------- ### mmToPt(mm) Source: https://reamkit.dev/api/index/functions/mmtopt Converts a value from millimeters to points. ```APIDOC ## mmToPt ### Description Converts a measurement in millimeters to points (pt). The conversion uses the standard ratio where 25.4 mm equals 1 inch, which is equivalent to 72 pt. ### Parameters - **mm** (number) - The value in millimeters to be converted. ### Returns - **Pt** (number) - The converted value in points. ``` -------------------------------- ### createLanguageHyphenator(language, bundle) Source: https://reamkit.dev/api/index/functions/createlanguagehyphenator Creates a Hyphenator instance from pre-loaded pattern strings. ```APIDOC ## createLanguageHyphenator(language, bundle) ### Description Synchronous variant of getHyphenator that builds a Hyphenator from already-loaded pattern strings. This is useful when patterns are bundled or fetched out-of-band. ### Signature `createLanguageHyphenator(language: SupportedLanguage, bundle: { patterns: string, exceptions?: string }): Hyphenator` ### Parameters - **language** (SupportedLanguage) - The language used to select the left/right minimums. - **bundle** (Object) - The pattern and optional exception strings. - **patterns** (string) - The pattern strings. - **exceptions** (string, optional) - The exception strings. ### Returns - **Hyphenator** - The constructed hyphenator instance. ``` -------------------------------- ### FetchFontSetOptions Interface Source: https://reamkit.dev/api/index/interfaces/fetchfontsetoptions Configuration object for the fetchFontSet operation. ```APIDOC ## Interface: FetchFontSetOptions ### Description Options for configuring the fetchFontSet function. ### Properties - **family** (string) - Optional - Document font family name to substitute, or a curated FamilyKey directly. - **fetch** (FetchLike) - Optional - Injectable fetch implementation (defaults to the global fetch); allows for offline testing. ``` -------------------------------- ### FontRegistry.fromBytes() Source: https://reamkit.dev/api/index/classes/fontregistry Creates a new FontRegistry instance by parsing a set of font bytes. ```APIDOC ## static fromBytes(input) ### Description Parses a set of font bytes into a registry. The input must contain at least the regular variant. ### Parameters - **input** (FontBytesByVariant) - Required - The bytes per variant. ### Returns - **FontRegistry** - A registry holding the parsed faces. ``` -------------------------------- ### splitPatternBundle(bundle) Source: https://reamkit.dev/api/index/functions/splitpatternbundle Splits a TeX-style pattern bundle string into an array of individual patterns. ```APIDOC ## splitPatternBundle ### Description Splits a TeX-style pattern bundle (a whitespace-separated string) into the pattern array that the createHyphenator function expects. ### Signature `splitPatternBundle(bundle: string): string[]` ### Parameters - **bundle** (string) - The whitespace-separated patterns to be split. ### Returns - **string[]** - An array of patterns with empty entries removed. ``` -------------------------------- ### twipsToPt(twips) Source: https://reamkit.dev/api/index/functions/twipstopt Converts a measurement in twips to points (Pt). ```APIDOC ## twipsToPt ### Description Converts a numeric value from twips to points (Pt). ### Signature `twipsToPt(twips: number): Pt` ### Parameters - **twips** (number) - The value in twips to be converted. ``` -------------------------------- ### Handle SmartArt with conversion reporting Source: https://reamkit.dev/guides/examples Use convertWithReport to identify dropped SmartArt elements that lack pre-rendered DrawingML fallbacks. ```typescript import { Ream } from 'reamkit'; const { bytes, losses } = await Ream.parse(docxBytes).convertWithReport('pdf', { fonts }); // a SmartArt with no drawing override → { severity: 'dropped', feature: 'shapes.smartArt', … } ``` -------------------------------- ### Convert PowerPoint to PDF or HTML Source: https://reamkit.dev/guides/examples Parses a .pptx file and converts it into either a PDF or flowed HTML document. ```javascript import { Ream } from 'reamkit'; const doc = Ream.parse(pptxBytes); // doc.format === 'pptx' const pdf = await doc.convert('pdf', { fonts }); // a page per slide const html = await doc.convert('html'); // …or the slides as flowed HTML ``` -------------------------------- ### ids() Source: https://reamkit.dev/api/index/classes/resourcestore Returns a list of all stored ResourceIds. ```APIDOC ## ids() ### Description Returns all stored ids in insertion order. ### Returns - **readonly ResourceId[]** - An array of all stored identifiers. ``` -------------------------------- ### Configure Font Resolution Chain Source: https://reamkit.dev/guides/examples Defines a priority-based font provider chain. The first provider to return bytes wins, and failures are recorded in the conversion report. ```javascript import { Ream, callerFontProvider, localFontProvider, remoteFontProvider } from 'reamkit'; const { bytes, losses } = await doc.convertWithReport('pdf', { fontProviders: [ callerFontProvider(myFonts), // your bytes first localFontProvider(), // system fonts (Chromium Local Font Access; // embedding-restricted fonts are never used) remoteFontProvider(), // open substitute set, last resort ], }); // losses[0] → { severity: 'substituted', feature: 'fonts.substitution', … } ``` -------------------------------- ### Convert Excel Pivot Tables Source: https://reamkit.dev/guides/examples Renders pivot tables with applied styles and formatting without recomputing the cache. ```typescript import { Ream } from 'reamkit'; const doc = Ream.parse(xlsxBytes); const pdf = await doc.convert('pdf', { fonts }); const html = await doc.convert('html'); ``` -------------------------------- ### renderStyledPdf(body, options) Source: https://reamkit.dev/api/index/functions/renderstyledpdf Renders a body to a PDF by laying it out and emitting it over a fresh PdfDocument. This is a byte-stable synchronous operation. ```APIDOC ## renderStyledPdf ### Description Render a body to a PDF: lay it out, then emit it over a fresh PdfDocument. The byte-stable synchronous path. ### Signature `renderStyledPdf(body: BodyElement[], options: StyledRenderOptions): Uint8Array` ### Parameters - **body** (BodyElement[]) - Required - The elements to render into the PDF. - **options** (StyledRenderOptions) - Required - Configuration options for the rendering process. ### Returns - **Uint8Array** - The rendered PDF document as a byte array. ### Throws - **Error** - Thrown when `options.encrypt` is set, as encryption requires the asynchronous `renderStyledPdfEncrypted` path. ``` -------------------------------- ### Enable PDF hyphenation Source: https://reamkit.dev/guides/examples Initialize a hyphenator for a specific locale and pass it to the convert method to enable automatic hyphenation. ```javascript import { getHyphenator } from 'reamkit'; const hyphenator = await getHyphenator('en-us'); // or 'ru' const pdf = await doc.convert('pdf', { fonts, hyphenator }); ``` -------------------------------- ### Ream.convertWithReport() Source: https://reamkit.dev/api/index/classes/ream Converts the document and returns both the output bytes and a loss report. ```APIDOC ## Ream.convertWithReport(to, options?) ### Description Convert the parsed document to `to`, returning the output bytes together with the accumulated Loss report. ### Parameters - **to** (ReamTarget) - Required - The target format. 'xlsx' requires a spreadsheet source. - **options** (ReamConvertOptions) - Optional - Font resolution and target-specific options. ### Returns - **Promise** - The encoded bytes and the loss report. ### Throws - Error when `to` is 'xlsx' but the source has no grid. - ConversionLossError when `options.strict` is set and any loss was recorded. ``` -------------------------------- ### chainProviders(providers) Source: https://reamkit.dev/api/index/functions/chainproviders Combines an array of FontProvider instances into a single FontProvider. The function iterates through the provided list, returning the first successful byte-level result, or falling through if a provider returns 'none'. ```APIDOC ## chainProviders ### Description Combines multiple font providers into a single provider. The first provider to return a byte-level answer is used; if a provider returns 'none', the system falls through to the next provider in the chain. ### Signature `chainProviders(providers: FontProvider[]): FontProvider` ### Parameters - **providers** (FontProvider[]) - Required - An array of font providers to be chained together. ### Returns - **FontProvider** - A new FontProvider instance that aggregates the behavior of the provided list. ``` -------------------------------- ### FontRegistry.entries() Source: https://reamkit.dev/api/index/classes/fontregistry Iterates over all font variants and their corresponding parsed fonts. ```APIDOC ## entries() ### Description Iterate the [variant, parsed font] pairs the registry holds. ### Returns - **IterableIterator<[FontVariant, ParsedTtf]>** - An iterator of the registry entries. ``` -------------------------------- ### Handle encrypted PDFs Source: https://reamkit.dev/guides/examples Provides methods for opening password-protected PDFs and handling decryption failures. ```javascript const doc = Ream.parse(pdfBytes, { password: 'letmein' }); ``` ```javascript const doc = Ream.parse(lockedPdf); // no/incorrect password doc.losses; // [ // { // severity: 'dropped', // feature: 'text', // detail: 'encrypted PDF — the user password was missing or incorrect, or the handler is unsupported', // }, // ] ``` ```javascript import { Ream, ConversionLossError } from 'reamkit'; try { await Ream.parse(lockedPdf).convert('html', { strict: true }); } catch (err) { if (err instanceof ConversionLossError) { err.loss.feature; // 'text' err.loss.detail; // 'encrypted PDF — the user password was missing or incorrect, …' } } ``` -------------------------------- ### callerFontProvider(fonts) Source: https://reamkit.dev/api/index/functions/callerfontprovider Creates a FontProvider that answers every font family request using the provided font bytes. It implements a fallback mechanism from bold/italic variants to regular if necessary. ```APIDOC ## callerFontProvider ### Description Creates a `FontProvider` that uses caller-supplied font bytes. This provider answers every family request and falls back through bold/italic variants to regular, similar to the standard registry. ### Signature `callerFontProvider(fonts: FontBytesByVariant): FontProvider` ### Parameters - **fonts** (`FontBytesByVariant`) - The collection of font bytes mapped by their variants to be used by the provider. ### Returns - **FontProvider** - A configured font provider instance. ``` -------------------------------- ### detect(bytes) Source: https://reamkit.dev/api/index/interfaces/converter Detects the input format of the provided bytes using reader sniffing. ```APIDOC ## detect(bytes) ### Description Detects the input format by reader sniffing. Returns undefined if the format is unknown. ### Parameters - **bytes** (Uint8Array) - Required - The input data to analyze. ### Returns - **DocumentReader | undefined** - The reader associated with the detected format, or undefined. ``` -------------------------------- ### Inspect Document Interlayer Source: https://reamkit.dev/guides/examples Access the format-neutral tree and metadata using Ream.parse before rendering occurs. ```javascript const doc = Ream.parse(bytes); doc.format; // 'docx' | 'xlsx' doc.losses; // read-time losses for (const el of doc.flow.body) { // el.kind: 'paragraph' | 'table' | 'image' | 'chart' | 'shape' } ``` -------------------------------- ### put(bytes) Source: https://reamkit.dev/api/index/classes/resourcestore Stores binary data and returns a content-addressed ResourceId. ```APIDOC ## put(bytes) ### Description Stores the provided bytes and returns their content-addressed id. If identical bytes are already stored, the existing id is returned (deduplication). ### Parameters - **bytes** (Uint8Array) - The binary data to store. ### Returns - **ResourceId** - The content-addressed identifier for the stored bytes. ``` -------------------------------- ### Re-emit an XLSX workbook Source: https://reamkit.dev/guides/examples Demonstrates how to parse an XLSX file and convert it back to the same format, ensuring lossless preservation of the grid surface. ```javascript import { Ream } from 'reamkit'; const doc = Ream.parse(xlsxBytes); // a .xlsx const out = await doc.convert('xlsx'); // `out` is a fresh, valid .xlsx — normalize, sanitize, or re-parse it. ``` -------------------------------- ### Provide custom fonts Source: https://reamkit.dev/guides/getting-started Pass font bytes directly to the convert method to avoid network I/O. ```javascript const fonts = { regular: new Uint8Array(await fetch('/fonts/MyFont-Regular.ttf').then((r) => r.arrayBuffer())), bold: new Uint8Array(await fetch('/fonts/MyFont-Bold.ttf').then((r) => r.arrayBuffer())), }; const pdf = await Ream.parse(bytes).convert('pdf', { fonts }); ``` -------------------------------- ### getHyphenator(language) Source: https://reamkit.dev/api/index/functions/gethyphenator Lazily build and cache a language’s Hyphenator instance. ```APIDOC ## getHyphenator(language) ### Description Lazily build and cache a language’s Hyphenator. The patterns module is dynamically imported the first time a language is requested, so callers that never hyphenate pay no cold-start cost. ### Signature `getHyphenator(language: SupportedLanguage): Promise` ### Parameters - **language** (SupportedLanguage) - Required - The language to load. ### Returns - **Promise** - The cached hyphenator. ``` -------------------------------- ### Enable Strict Mode Source: https://reamkit.dev/guides/examples Set strict to true to throw a ConversionLossError when document degradation occurs during conversion. ```javascript import { ConversionLossError } from 'reamkit'; try { await doc.convert('pdf', { fonts, strict: true }); } catch (e) { if (e instanceof ConversionLossError) { // e.loss — what exactly would have been dropped/degraded/substituted } } ``` -------------------------------- ### SvgWriteOptions Source: https://reamkit.dev/api/index/interfaces/svgwriteoptions The SvgWriteOptions interface provides configuration options for SVG output generation. ```APIDOC ## SvgWriteOptions ### Description Configuration options for the `writeSvg` function. ### Properties - **pageGap** (number) - Optional - Gap between stacked pages, in px/pt (default 12). ``` -------------------------------- ### Ream.convert() Source: https://reamkit.dev/api/index/classes/ream Converts the parsed document to a specified target format and returns the output bytes. ```APIDOC ## Ream.convert(to, options?) ### Description Convert the parsed document to `to` and return just the output bytes. A thin wrapper over Ream.convertWithReport that drops the loss report. ### Parameters - **to** (ReamTarget) - Required - The target format. - **options** (ReamConvertOptions) - Optional - Font resolution and target-specific options. ### Returns - **Promise** - The encoded output bytes. ``` -------------------------------- ### Apply Digital Signatures to PDFs Source: https://reamkit.dev/guides/examples Implements PKCS#7 detached signatures using WebCrypto. Requires a DER-encoded certificate and a WebCrypto CryptoKey. ```javascript const signed = await doc.convert('pdf', { fonts, signature: { certificate: certificateDer, // Uint8Array, DER privateKey: cryptoKey, // WebCrypto CryptoKey // optional: signingTime, reason, location, pades: true, timestampUrl }, }); ``` -------------------------------- ### Convert documents with Ream Source: https://reamkit.dev/llms.txt Parses input bytes and converts them to a target format. The library automatically detects the source format from the provided bytes. ```ts import { Ream } from 'reamkit'; const doc = Ream.parse(bytes); // format sniffed from the bytes const pdf = await doc.convert('pdf'); // one parse, any target ``` -------------------------------- ### has(id) Source: https://reamkit.dev/api/index/classes/resourcestore Checks if a specific ResourceId exists in the store. ```APIDOC ## has(id) ### Description Checks whether an id is present in the store. ### Parameters - **id** (ResourceId) - The identifier to check. ### Returns - **boolean** - True if the id exists, false otherwise. ``` -------------------------------- ### CreateConverterOptions Source: https://reamkit.dev/api/index/interfaces/createconverteroptions Configuration options for the createConverter function, specifically for managing document readers. ```APIDOC ## Interface: CreateConverterOptions ### Description Options for the `createConverter` function. This interface allows for the customization of the document reader registry. ### Properties - **readers?** (readonly DocumentReader[]) - Optional - Override or extend the reader registry (defaults to DEFAULT_READERS). ``` -------------------------------- ### Generate Accessible PDF/UA-1 Documents Source: https://reamkit.dev/guides/examples Enables ISO 14289-1 compliance. Can be combined with PDF/A settings for archival-grade accessible files. ```javascript const accessible = await doc.convert('pdf', { fonts, pdfUA: true }); const archival = await doc.convert('pdf', { fonts, pdfA: 'PDF/A-2a', pdfUA: true }); ``` -------------------------------- ### emuToPt(emu) Source: https://reamkit.dev/api/index/functions/emutopt Converts a value from English Metric Units (EMU) to points (Pt). ```APIDOC ## emuToPt(emu) ### Description Converts English Metric Units (EMU) to points (Pt). 914400 EMU equals 1 inch, which is 72 pt, resulting in a conversion factor of 12700 EMU per 1 pt. ### Parameters - **emu** (number) - The value in English Metric Units to convert. ### Returns - **Pt** (number) - The converted value in points. ``` -------------------------------- ### FontRegistry.resolveByStyle() Source: https://reamkit.dev/api/index/classes/fontregistry Resolves a style request to the closest available font face. ```APIDOC ## resolveByStyle(bold, italic) ### Description Resolve a style request to the closest available face, degrading through bold and italic if an exact match is missing. ### Parameters - **bold** (boolean) - Required - Whether bold was requested. - **italic** (boolean) - Required - Whether italic was requested. ### Returns - **object** - The chosen variant and its parsed font. - **parsed** (ParsedTtf) - **variant** (FontVariant) ### Throws - Error when the registry has no usable (regular) font. ``` -------------------------------- ### inchToPt(inches) Source: https://reamkit.dev/api/index/functions/inchtopt Converts a value from inches to points (pt). ```APIDOC ## inchToPt ### Description Converts a measurement provided in inches to points (pt). The conversion factor used is 1 inch = 72 pt. ### Signature `inchToPt(inches: number): Pt` ### Parameters - **inches** (number) - The measurement in inches to be converted. ### Returns - **Pt** - The converted measurement in points. ``` -------------------------------- ### resolveFamilyKey(name) Source: https://reamkit.dev/api/index/functions/resolvefamilykey Maps a font family name to a FamilyKey, returning a metric twin or style fallback. ```APIDOC ## resolveFamilyKey(name) ### Description Maps a document-referenced font family to a curated open substitute. It returns an exact metric twin when one is known (e.g., Calibri → Carlito), otherwise it provides a serif, mono, or sans style fallback. ### Signature `resolveFamilyKey(name: string | undefined): FamilyKey` ### Parameters - **name** (string | undefined) - The referenced family name (case-insensitive). If empty, defaults to Arimo. ### Returns - **FamilyKey** - The chosen FamilyKey object. ``` -------------------------------- ### Convert Excel Slicers Source: https://reamkit.dev/guides/examples Renders slicers as captioned button boxes following the grid output. ```typescript import { Ream } from 'reamkit'; const doc = Ream.parse(xlsxBytes); const pdf = await doc.convert('pdf', { fonts }); // a button box per slicer, after the grid const html = await doc.convert('html'); ``` -------------------------------- ### signPdf(pdf, cred) Source: https://reamkit.dev/api/index/functions/signpdf Signs a PDF that already contains a signature placeholder by injecting the cryptographic signature into the reserved contents. ```APIDOC ## signPdf(pdf, cred) ### Description Signs a PDF that already carries a signature placeholder (from addSignaturePlaceholder). It computes the real /ByteRange, hashes the covered bytes (SHA-256), builds the detached PKCS#7/CMS, and writes it into the reserved /Contents hole. ### Signature `signPdf(pdf: Uint8Array, cred: SignerCredentials): Promise>` ### Parameters - **pdf** (Uint8Array) - The placeholder-bearing PDF bytes. - **cred** (SignerCredentials) - The signer’s certificate, key, and algorithm. ### Returns - **Promise>** - A new byte array with the real ByteRange and signature spliced in. ### Throws - **Error** - Thrown when no placeholder is found, it is malformed, WebCrypto is unavailable, or the signature exceeds the reserved /Contents size. ``` -------------------------------- ### Convert documents Source: https://reamkit.dev/guides/getting-started Parse document bytes into the interlayer and convert to various target formats. The format is automatically detected from the input bytes. ```javascript import { Ream } from 'reamkit'; // e.g. from an or a fetch() — anything that yields bytes. const bytes = new Uint8Array(await file.arrayBuffer()); const doc = Ream.parse(bytes); // docx, xlsx, pptx or pdf — sniffed const pdf = await doc.convert('pdf'); // async — fetches a font if needed const svg = await doc.convert('svg'); // same parse, different target const html = await doc.convert('html'); // flowed HTML — needs no fonts at all const docx = await doc.convert('docx'); // WordprocessingML back out const xlsx = await doc.convert('xlsx'); // SpreadsheetML back out (xlsx source) // Hand the bytes to the browser: preview, download, upload, … const url = URL.createObjectURL(new Blob([pdf], { type: 'application/pdf' })); window.open(url); ``` -------------------------------- ### layoutStyledDocument(body, options) Source: https://reamkit.dev/api/index/functions/layoutstyleddocument Performs the layout phase (FlowDoc to PageDoc transform), driving numbering, geometry, block layout, and pagination to return a LaidOutPdfDocument. ```APIDOC ## layoutStyledDocument ### Description Performs the layout phase (the FlowDoc→PageDoc transform) of the document. It processes the document body into positioned pages, font/image resources, and logical structure, returning a LaidOutPdfDocument. ### Signature `layoutStyledDocument(body: BodyElement[], options: StyledRenderOptions): LaidOutPdfDocument` ### Parameters - **body** (BodyElement[]) - The document body the section model partitions. - **options** (StyledRenderOptions) - The resolved fonts, styles, section model, and PDF-output toggles. ### Returns - **LaidOutPdfDocument** - The positioned pages plus the PDF-only PdfLayoutAux companion. ``` -------------------------------- ### writeHtml(flow) Source: https://reamkit.dev/api/index/functions/writehtml Renders a FlowDoc to a self-contained HTML document. ```APIDOC ## writeHtml(flow) ### Description Render a FlowDoc to a self-contained HTML document. This is a pure, zero-I/O transform where flow body properties map directly to CSS and charts/shapes are emitted as inline SVG. ### Signature `writeHtml(flow: FlowDoc): WriteResult` ### Parameters - **flow** (FlowDoc) - Required - The format-neutral interlayer document tree. ### Returns - **WriteResult** - The encoded HTML bytes plus the recorded Loss list. ```