API reference
Every class, method and function of the NexPDF Web SDK, grouped by feature. Generated from NexPDF 1.1.0.
Generated from NexPDF 1.1.0
This page is generated from the sources of @nexdevit/nexpdf-web. It lists 223 members. Options and results that are JSON strings use the same JSON in every NexPDF SDK. Module is the license module a call needs; calls marked "always available" work without a license key.
The high-level PdfDocument and NexPdfEngine come first; doc.raw (a WasmDocument) exposes every function of the C SDK and is listed by feature below.
Setup and lifecycle
loadNexPdf
loadNexPdf(wasmUrl?: string | URL): Promise<NexPdfEngine>Loads and instantiates the WebAssembly module once and returns the engine. wasmUrl overrides where nexpdf_bg.wasm is fetched from.
On @nexdevit/nexpdf-web/engine
width
nex.width: numberOn NexPdfEngine
height
nex.height: numberOn NexPdfEngine
rotation
nex.rotation: numberOn NexPdfEngine
userUnit
nex.userUnit: numberOn NexPdfEngine
crop
nex.crop: RectOn NexPdfEngine
toDisplay
nex.toDisplay: [number, number, number, number, number, number]PDF user space to display points: x' = a·x + c·y + e, y' = b·x + d·y + f.
On NexPdfEngine
toView
nex.toView(x: number, y: number, scale = 1): [number, number]PDF point to display pixels.
On NexPdfEngine
toPdf
nex.toPdf(vx: number, vy: number, scale = 1): [number, number]Display pixels (e.g. a tap) to a PDF point.
On NexPdfEngine
deltaToPdf
nex.deltaToPdf(dx: number, dy: number, scale = 1): [number, number]A displacement on screen (pixels) as a displacement in PDF space.
On NexPdfEngine
rectToView
nex.rectToView([llx, lly, urx, ury]: Rect, scale = 1)PDF rect to { left, top, width, height } in display pixels.
On NexPdfEngine
rectToPdf
nex.rectToPdf(x1: number, y1: number, x2: number, y2: number, scale = 1): RectDisplay rect (any two corners, pixels) to a PDF rect.
On NexPdfEngine
fromBytes
PdfDocument.fromBytes(bytes: Uint8Array, options: { password?: string } = {}): PdfDocumentA PDF (pass password when it is encrypted), or a Word / Excel / PowerPoint file, an EPUB / FictionBook / XPS book or a CBZ comic (converted). A missing or wrong password throws an OpenError with passwordRequired (and wrongPassword) set.
On PdfDocument
fromEbook
PdfDocument.fromEbook(bytes: Uint8Array): PdfDocumentEPUB, FictionBook (.fb2 / .fb2.zip), XPS / OpenXPS or CBZ, converted (module: conversion).
On PdfDocument
fromOffice
PdfDocument.fromOffice(bytes: Uint8Array): PdfDocumentWord / Excel / PowerPoint, converted (module: conversion).
On PdfDocument
fromFile
PdfDocument.fromFile(file: Blob, options: { password?: string } = {}): Promise<PdfDocument>On PdfDocument
fromUrl
PdfDocument.fromUrl(url: string, options: { password?: string } = {}): Promise<PdfDocument>On PdfDocument
fromHtml
PdfDocument.fromHtml(html: string): PdfDocumentOn PdfDocument
pageCount
doc.pageCount: numberOn PdfDocument
pageSize
doc.pageSize(page: number)Displayed page size in points: the crop box (clipped to the media box), after /Rotate and /UserUnit.
On PdfDocument
pageView
doc.pageView(page: number): PageViewHow a page is displayed, and the transform between PDF and display coordinates (see PageView).
On PdfDocument
text
doc.text(page: number): stringOn PdfDocument
markdown
doc.markdown(): stringOn PdfDocument
search
doc.search(query: string)On PdfDocument
metadata
doc.metadata()On PdfDocument
security
doc.security()On PdfDocument
pageLabels
doc.pageLabels(): { labels: string[]; ranges: PageLabelRange[] }{ labels: ['i', 'ii', '1'], ranges: [{ start, style, prefix, first }] }.
On PdfDocument
setPageLabels
doc.setPageLabels(ranges: PageLabelRange[]): number[] removes the labels (module: editor).
On PdfDocument
toBytes
doc.toBytes(): Uint8ArrayOn PdfDocument
toLinearizedBytes
doc.toLinearizedBytes(): Uint8ArrayLinearized ("Fast Web View") PDF bytes: the first page shows before the download ends.
On PdfDocument
toBlob
doc.toBlob(): BlobThe document as a Blob, e.g. for URL.createObjectURL or a download link.
On PdfDocument
render
doc.render(page: number, options: { dpi?: number } = {}): Uint8ArrayPNG bytes of a page.
On PdfDocument
renderUrl
doc.renderUrl(page: number, options: { dpi?: number } = {}): stringA page as an object URL (revoke it when done).
On PdfDocument
toDocx
doc.toDocx(): Uint8ArrayOn PdfDocument
toXlsx
doc.toXlsx(): Uint8ArrayOn PdfDocument
toPptx
doc.toPptx(): Uint8ArrayOn PdfDocument
toReflowHtml
doc.toReflowHtml(options?: { pages?: number[]; images?: boolean; full_page?: boolean; title?: string }): stringOn PdfDocument
annotations
doc.annotations(page: number)On PdfDocument
addAnnotation
doc.addAnnotation(a: { page?: number; kind: string; color?: string; opacity?: number; contents?: string; rect: Rect }): numberOn PdfDocument
addImageStamp
doc.addImageStamp(s: { page?: number; rect: Rect; rgba: Uint8Array; width: number; height: number; opacity?: number }): numberOn PdfDocument
addMeasurement
doc.addMeasurement(page: number, m: { kind: 'distance' | 'perimeter' | 'area'; points: Array<[number, number]>; unit?: string; per_point?: number; label?: string })On PdfDocument
measurements
doc.measurements()On PdfDocument
setBackground
doc.setBackground(options: { color?: string | null; fit?: string; scale?: number; opacity?: number; pages?: number[] } = {}, image?: { rgb: Uint8Array; width: number; height: number }): numberOn PdfDocument
formFields
doc.formFields()On PdfDocument
fillField
doc.fillField(name: string, value: string | number | boolean): numberOn PdfDocument
flattenForms
doc.flattenForms(): numberOn PdfDocument
setSignatureAppearance
doc.setSignatureAppearance(name: string, rgba: Uint8Array, width: number, height: number): numberShows a drawn, typed or scanned signature (RGBA pixels) in a signature field, without signing it digitally.
On PdfDocument
ocr
doc.ocr(options?: { engine?: 'builtin'; languages?: string; dpi?: number; pages?: number[]; force?: boolean })On PdfDocument
redact
doc.redact(page: number, [llx, lly, urx, ury]: Rect, fillWhite = false): numberOn PdfDocument
encrypt
doc.encrypt(userPassword: string, ownerPassword: string): numberOn PdfDocument
sign
doc.sign(p12: Uint8Array, password: string, options?: Record<string, unknown>): Uint8ArrayOn PdfDocument
signOnline
doc.signOnline(p12: Uint8Array, password: string, options: SignOnlineOptions = {}): Promise<Uint8Array>Signs at any PAdES level: { level: 'B-T' | 'B-LT' | 'B-LTA', tsaUrl, … } plus the options of sign. The engine signs, then fetch gets the time-stamps and OCSP / CRL data.
On PdfDocument
prepareExternalSignature
doc.prepareExternalSignature(cert: Uint8Array, options?: Record<string, unknown>): Uint8ArrayExternal signing, step 1: this document with an empty signature. cert is the signer certificate (PEM or DER, optionally with its chain). Then nex.externalSignatureData and nex.completeExternalSignature.
On PdfDocument
merge
doc.merge(other: PdfDocument): numberOn PdfDocument
trimMemory
doc.trimMemory(): numberCompacts internal buffers; returns the approximate number of bytes reclaimed.
On PdfDocument
memoryUsage
doc.memoryUsage(): numberEstimated memory used by this document, in bytes.
On PdfDocument
close
doc.close(): voidOn PdfDocument
clone
raw.clone(): WasmDocumentA copy of this document.
On WasmDocument
setAnnotationFlags
raw.setAnnotationFlags(num: number, generation: number, flags_json?: string | null): numberAnnotation flags (/F). flags_json: {"readonly":true,"print":false} changes only the flags it names; ["print","locked"] sets exactly these; a number is the bitmask. Names: invisible, hidden, print, nozoom, norotate, noview, readonly, locked, togglenoview, lockedcontents. XFDF import and export keep them (flags="print,readonly"). 1 on success.
On WasmDocument
setAnnotationStyle
raw.setAnnotationStyle(num: number, generation: number, style_json?: string | null): numberColour, opacity and border width, then a new appearance: {"color":"#RRGGBB","opacity":0.5, "border_width":2}, every key optional (a missing key keeps the current value). 1 on success.
On WasmDocument
Viewer component (iframe)
createNexPdfViewer
createNexPdfViewer(options: NexPdfViewerOptions): NexPdfViewerCreates a viewer in options.container and loads it from the NexPDF WebViewer server.
On @nexdevit/nexpdf-web
ready
viewer.ready(): Promise<ViewerState>Resolves once the viewer has loaded its first document.
On NexPdfViewer
on
viewer.on(event: K, fn: Listener<K>): () => voidSubscribes to a viewer event; returns an unsubscribe function.
On NexPdfViewer
off
viewer.off(event: K, fn: Listener<K>): voidOn NexPdfViewer
setConfig
viewer.setConfig(config: NexPdfUIConfig): Promise<void>Replaces the whole UI configuration.
On NexPdfViewer
updateConfig
viewer.updateConfig(config: NexPdfUIConfig): Promise<void>Deep-merges a partial configuration into the current one.
On NexPdfViewer
getConfig
viewer.getConfig(): NexPdfUIConfigOn NexPdfViewer
setMode
viewer.setMode(mode: ViewerMode)On NexPdfViewer
setTheme
viewer.setTheme(theme: 'light' | 'dark' | 'system')On NexPdfViewer
setLanguage
viewer.setLanguage(language: string)On NexPdfViewer
goToPage
viewer.goToPage(page: number)1-based page number.
On NexPdfViewer
setAnnotationTool
viewer.setAnnotationTool(tool: AnnotationTool | 'select')On NexPdfViewer
disableElements
viewer.disableElements(ids: ToolbarItem[])Hides built-in items (same ids as toolbarConfig.hiddenItems).
On NexPdfViewer
enableElements
viewer.enableElements(ids: ToolbarItem[])On NexPdfViewer
setCustomStyle
viewer.setCustomStyle(css: string)Injects a stylesheet into the viewer (replaces the previous one).
On NexPdfViewer
undo
viewer.undo()On NexPdfViewer
redo
viewer.redo()On NexPdfViewer
getState
viewer.getState()On NexPdfViewer
loadDocument
viewer.loadDocument(source: string | File | Uint8Array, filename = 'document.pdf'): Promise<ViewerState>Loads a PDF (or DOCX/XLSX/PPTX) from a URL, File, or Uint8Array.
On NexPdfViewer
getDocument
viewer.getDocument(): Promise<Blob>The current PDF, with every change applied.
On NexPdfViewer
exportAs
viewer.exportAs(format: 'docx' | 'xlsx' | 'pptx' | 'html' | 'csv' | 'json' | 'xml' | 'rtf' | 'md'): Promise<Blob>Exports the current PDF to DOCX, XLSX, PPTX, HTML, CSV, JSON, XML, RTF, or Markdown.
On NexPdfViewer
search
viewer.search(query: string, caseSensitive = false, wholeWord = false)Searches the document and returns matches with context snippets and PDF bounding boxes.
On NexPdfViewer
destroy
viewer.destroy(): voidUnmounts the viewer and cleans up DOM resources.
On NexPdfViewer
Opening and saving
saveBytes
raw.saveBytes(): Uint8ArrayThe document, with every change, as PDF bytes (full rewrite).
On WasmDocument · always available · C nexpdf_save_bytes
saveLinearized
raw.saveLinearized(): Uint8ArrayA linearized ("Fast Web View") PDF: the first page shows before the download ends.
On WasmDocument · always available · C nexpdf_save_linearized
Pages and rendering
pageCount
raw.pageCount(): numberNumber of pages.
On WasmDocument · always available · C nexpdf_page_count
pageWidth
raw.pageWidth(page_index: number): numberDisplayed page width in points (crop box, rotation and /UserUnit applied).
On WasmDocument · always available · C nexpdf_page_width
pageHeight
raw.pageHeight(page_index: number): numberDisplayed page height in points (crop box, rotation and /UserUnit applied).
On WasmDocument · always available · C nexpdf_page_height
pageViewJson
raw.pageViewJson(page_index: number): stringHow the page is displayed: width, height, rotation, user_unit, crop and the PDF-to-display matrix to_display.
On WasmDocument · always available · C nexpdf_page_view_json
renderPagePng
raw.renderPagePng(page_index: number, dpi: number): Uint8ArrayRenders a page to PNG at the given resolution (dots per inch). Unlicensed and trial renders carry a watermark.
On WasmDocument · always available · C nexpdf_render_page_png
renderThumbPng
raw.renderThumbPng(page_index: number, max_dim: number): Uint8ArrayRenders a thumbnail PNG whose longer side is at most max_dim pixels.
On WasmDocument · always available · C nexpdf_render_thumb_png
setOverprint
raw.setOverprint(mode: number): numberOverprint simulation for later renders: 0 = PDF/X documents only (default), 1 = always, 2 = never.
On WasmDocument · always available · C nexpdf_set_overprint
Text, search and assistant
extractPageText
raw.extractPageText(page_index: number): stringThe text of a page in reading order.
On WasmDocument · always available · C nexpdf_extract_page_text
extractMarkdown
raw.extractMarkdown(): stringThe whole document as Markdown (headings, lists, tables).
On WasmDocument · always available · C nexpdf_extract_markdown
searchJson
raw.searchJson(query?: string | null): stringFinds a text in every page (case-insensitive). Returns a JSON array of hits: page, context and the rectangle llx, lly, urx, ury in PDF points.
On WasmDocument · always available · C nexpdf_search_json
pageBlocksJson
raw.pageBlocksJson(page_index: number): stringThe text blocks of a page as JSON: text, font size and the rectangle llx, lly, urx, ury.
On WasmDocument · always available · C nexpdf_page_blocks_json
askDocument
raw.askDocument(question: string | null | undefined, k: number, max_chars: number): stringDocument assistant retrieval, offline (BM25): the k passages most relevant to a question and a page-tagged context of at most max_chars characters (0 = 200000) to send to a language model. Returns {"passages":[{"page","text","score"}],"context":"...","context_pages":[...]}.
On WasmDocument · always available · C nexpdf_ask_document
pageWordsJson
raw.pageWordsJson(page_index: number, options_json?: string | null): stringThe words of a page with exact boxes from the glyph widths and the text state: text, bbox, quad (follows rotated text), font, size, angle, line. {"glyphs":true} adds the glyph boxes.
On WasmDocument · always available · C nexpdf_page_words_json
Conversion
toHtml
raw.toHtml(): stringThe document as HTML.
On WasmDocument · module conversion · C nexpdf_to_html
toJson
raw.toJson(): stringThe document content as JSON.
On WasmDocument · module conversion · C nexpdf_to_json
toXml
raw.toXml(): stringThe document content as XML.
On WasmDocument · module conversion · C nexpdf_to_xml
toCsv
raw.toCsv(): stringTables of the document as CSV.
On WasmDocument · module conversion · C nexpdf_to_csv
toRtf
raw.toRtf(): stringThe document as RTF.
On WasmDocument · module conversion · C nexpdf_to_rtf
toDocx
raw.toDocx(): Uint8ArrayThe document as a Word (.docx) file.
On WasmDocument · module conversion · C nexpdf_to_docx
toXlsx
raw.toXlsx(): Uint8ArrayThe document as an Excel workbook, one sheet per page.
On WasmDocument · module conversion · C nexpdf_to_xlsx
toPptx
raw.toPptx(): Uint8ArrayThe document as a PowerPoint presentation, one slide per page.
On WasmDocument · module conversion · C nexpdf_to_pptx
toReflowHtml
raw.toReflowHtml(options_json?: string | null): stringThe text as responsive HTML for small screens. Options (may be omitted): {"pages":[0],"images":true,"full_page":true,"title":"..."}.
On WasmDocument · module conversion · C nexpdf_to_reflow_html
Templates
templateFillPdf
raw.templateFillPdf(data_json?: string | null, options_json?: string | null): numberFills a PDF template in place: AcroForm fields by name and placeholders in the page text. Options {"flatten","fields","text","strict","locale"}. Returns the number of fields and text lines filled.
On WasmDocument · module conversion · C nexpdf_template_fill_pdf
Structured extraction and barcodes
extractTablesJson
raw.extractTablesJson(page_index: number, options_json?: string | null): stringRuled and unruled tables of a page (every page when the index is negative) with cells, spans, CSV and Markdown. Options {"ruled","unruled","min_unruled_lines"}.
On WasmDocument · module conversion · C nexpdf_extract_tables_json
extractKeyValuesJson
raw.extractKeyValuesJson(options_json?: string | null): stringLabel/value pairs from the layout and typed entities (dates, amounts, IBANs, e-mails, phones, VAT numbers) with normalised values. Options {"pages","date_order"}.
On WasmDocument · module conversion · C nexpdf_extract_key_values_json
extractionPromptJson
raw.extractionPromptJson(schema_json?: string | null, options_json?: string | null): stringA prompt (system, prompt, response_schema) for extracting a JSON schema with the language model of your choice. The engine makes no network calls.
On WasmDocument · module conversion · C nexpdf_extraction_prompt_json
extractionValidateJson
raw.extractionValidateJson(schema_json?: string | null, answer_json?: string | null): stringValidates and coerces a model answer against the schema and grounds each value on the pages: valid, value, errors, warnings, fields.
On WasmDocument · module conversion · C nexpdf_extraction_validate_json
classifyDocumentJson
raw.classifyDocumentJson(labels_json?: string | null): stringClassifies the document into one of the given labels by keywords, with scores and a prompt for LLM classification.
On WasmDocument · module conversion · C nexpdf_classify_document_json
readBarcodesJson
raw.readBarcodesJson(page_index: number, options_json?: string | null): stringReads the barcodes of a page (every page when the index is negative): QR, Data Matrix, Aztec, PDF417, Code 128/39/93, EAN/UPC, ITF, Codabar and more, with positions in PDF points.
On WasmDocument · module conversion · C nexpdf_read_barcodes_json
addBarcode
raw.addBarcode(page_index: number, llx: number, lly: number, urx: number, ury: number, format?: string | null, text?: string | null): numberDraws text as a vector barcode (white background, quiet zone) into a rectangle of a page, in PDF points.
On WasmDocument · module editor · C nexpdf_add_barcode
addBarcodeEx
raw.addBarcodeEx(page_index: number, llx: number, lly: number, urx: number, ury: number, format?: string | null, text?: string | null, options_json?: string | null): numberDraws a vector barcode with options {"human_readable":"auto"|"always"|"never","quiet_zone","background","color"}; auto prints the digits under EAN and UPC codes.
On WasmDocument · module editor · C nexpdf_add_barcode_ex
Annotations
addAnnotation
raw.addAnnotation(pageIndex: number, kind: string | null, colorHex: string | null, opacity: number, contents: string | null, llx: number, lly: number, urx: number, ury: number): numberAdds an annotation. kind is a PDF annotation subtype such as Highlight, Underline, StrikeOut, Squiggly, Square, Circle, FreeText or Text; text markup is fitted to the lines under the rectangle. Colour is #RRGGBB, the rectangle is in PDF points.
On WasmDocument · module annotations · C nexpdf_add_annotation
addInk
raw.addInk(page_index: number, color_hex: string | null | undefined, stroke_width: number, opacity: number, coords?: string | null): numberAdds a freehand ink annotation. coords is "x,y;x,y;..." in PDF points.
On WasmDocument · module annotations · C nexpdf_add_ink
addLine
raw.addLine(page_index: number, kind: string | null | undefined, color_hex: string | null | undefined, opacity: number, stroke_width: number, x1: number, y1: number, x2: number, y2: number): numberAdds a line or arrow (kind is Line or Arrow) from (x1, y1) to (x2, y2) in PDF points.
On WasmDocument · module annotations · C nexpdf_add_line
annotationsJson
raw.annotationsJson(page_index: number): stringThe annotations of a page as JSON: num, gen, kind, color, contents and the rectangle.
On WasmDocument · always available · C nexpdf_annotations_json
removeAnnotation
raw.removeAnnotation(page_index: number, num: number, generation: number): numberRemoves the annotation with object number num and generation gen from a page.
On WasmDocument · module annotations · C nexpdf_remove_annotation
moveAnnotation
raw.moveAnnotation(num: number, generation: number, dx: number, dy: number): numberMoves an annotation by (dx, dy) PDF points.
On WasmDocument · module annotations · C nexpdf_move_annotation
setAnnotationContents
raw.setAnnotationContents(num: number, generation: number, contents?: string | null): numberReplaces the text contents of an annotation.
On WasmDocument · module annotations · C nexpdf_set_annotation_contents
exportXfdf
raw.exportXfdf(): stringExports every annotation as an XFDF document.
On WasmDocument · module annotations · C nexpdf_export_xfdf
importXfdf
raw.importXfdf(xfdf?: string | null): numberImports annotations from an XFDF document.
On WasmDocument · module annotations · C nexpdf_import_xfdf
flattenAnnotations
raw.flattenAnnotations(page_index: number): numberBurns annotations into the page content. A negative page index flattens every page.
On WasmDocument · module annotations · C nexpdf_flatten_annotations
addImageStamp
raw.addImageStamp(page: number, llx: number, lly: number, urx: number, ury: number, rgba: Uint8Array | number[], width: number, height: number, opacity: number): numberAdds a picture stamp annotation from RGBA pixels (transparency kept). 1 on success.
On WasmDocument · module annotations · C nexpdf_add_image_stamp
addMeasurement
raw.addMeasurement(page: number, json?: string | null): stringStores a measurement: {"kind":"distance|perimeter|area","points":[[x,y],...],"unit":"mm","per_point":0.3528,"label":"1:100","color":"#2f54d6"}. Returns {"num","gen","value","text"}.
On WasmDocument · module annotations · C nexpdf_add_measurement
measurementsJson
raw.measurementsJson(): stringThe stored measurements as JSON.
On WasmDocument · always available · C nexpdf_measurements_json
addFileAttachmentAnnot
raw.addFileAttachmentAnnot(page_index: number, x: number, y: number, name: string | null | undefined, data: Uint8Array | number[], mime?: string | null, description?: string | null): numberAdds a paperclip annotation carrying a file; (x, y) is the top-left corner of the icon in PDF points.
On WasmDocument · module annotations · C nexpdf_add_file_attachment_annot
addInkSignature
raw.addInkSignature(page_index: number, color_hex: string | null | undefined, stroke_width: number, strokes?: string | null): numberAdds a handwritten signature: an ink annotation with several strokes ("x,y;x,y|x,y;x,y", PDF points) and subject "Signature". Visual only; use a PAdES signature for a cryptographic one.
On WasmDocument · module annotations · C nexpdf_add_ink_signature
replyToAnnotation
raw.replyToAnnotation(page_index: number, num: number, generation: number, author?: string | null, text?: string | null): numberAdds a reply by author to an annotation (or to another reply). Returns the reply object number (generation 0).
On WasmDocument · module annotations · C nexpdf_reply_to_annotation
annotationRepliesJson
raw.annotationRepliesJson(page_index: number, num: number, generation: number): stringThe thread under an annotation, oldest first: num, gen, in_reply_to, author, date, text, state, state_model.
On WasmDocument · module annotations · C nexpdf_annotation_replies_json
setAnnotationState
raw.setAnnotationState(page_index: number, num: number, generation: number, author?: string | null, state?: string | null): numberSets a review state (Accepted, Rejected, Cancelled, Completed, None) or marked state (Marked, Unmarked) as a hidden state reply. Returns its object number.
On WasmDocument · module annotations · C nexpdf_set_annotation_state
Forms
formFieldsJson
raw.formFieldsJson(): stringThe form fields as JSON: name, kind, value, page, rectangle, read_only and required.
On WasmDocument · module forms · C nexpdf_form_fields_json
fillFormField
raw.fillFormField(name?: string | null, value?: string | null): numberSets a field value as a viewer would: the keystroke and validate scripts check the value, then every calculated field is recomputed. Check boxes take "true" or "false", list fields the option text.
On WasmDocument · module forms · C nexpdf_fill_form_field
setSignatureAppearance
raw.setSignatureAppearance(name: string | null | undefined, rgba: Uint8Array | number[], width: number, height: number): numberShows a drawn, typed or scanned signature (RGBA pixels) in a signature field without signing digitally; scaled to fit each widget and centred. A later digital signature replaces it.
On WasmDocument · module forms · C nexpdf_set_signature_appearance
addFormField
raw.addFormField(page_index: number, kind: string | null | undefined, name: string | null | undefined, llx: number, lly: number, urx: number, ury: number): numberAdds a form field named name in a rectangle of a page. kind: text (default), checkbox, radio, combobox, listbox, button, signature or barcode.
On WasmDocument · module forms · C nexpdf_add_form_field
flattenForms
raw.flattenForms(): numberBurns the form fields into the page content.
On WasmDocument · module forms · C nexpdf_flatten_forms
recalculateForms
raw.recalculateForms(): numberRuns every calculate script; returns how many fields changed.
On WasmDocument · module forms · C nexpdf_recalculate_forms
exportFormJson
raw.exportFormJson(): stringThe field values as a JSON object.
On WasmDocument · module forms · C nexpdf_export_form_json
importFormJson
raw.importFormJson(json?: string | null): numberFills fields from a JSON object of names and values.
On WasmDocument · module forms · C nexpdf_import_form_json
exportFormFdf
raw.exportFormFdf(pdf_name?: string | null): Uint8ArrayThe field values as an FDF file; pdf_name is the file name recorded in it.
On WasmDocument · module forms · C nexpdf_export_form_fdf
importFormFdf
raw.importFormFdf(data: Uint8Array | number[]): numberFills fields from an FDF file.
On WasmDocument · module forms · C nexpdf_import_form_fdf
exportFormXfdf
raw.exportFormXfdf(pdf_name?: string | null): stringThe field values as XFDF.
On WasmDocument · module forms · C nexpdf_export_form_xfdf
importFormXfdf
raw.importFormXfdf(xfdf?: string | null): numberFills fields from XFDF.
On WasmDocument · module forms · C nexpdf_import_form_xfdf
XFA forms
xfaInfoJson
raw.xfaInfoJson(): stringWhether the document has XFA, whether it is dynamic, field and data counts and the XDP packets.
On WasmDocument · module forms · C nexpdf_xfa_info_json
xfaExportData
raw.xfaExportData(format?: string | null): stringThe XFA data as xml (default) or flat json ({"path":"value"}). Fails when the document has no XFA.
On WasmDocument · module forms · C nexpdf_xfa_export_data
xfaImportData
raw.xfaImportData(data?: string | null, format?: string | null): numberImports XFA data: XML replaces the data, JSON sets the given values. Static forms get their AcroForm fields updated. Returns the number of values imported.
On WasmDocument · module forms · C nexpdf_xfa_import_data
xfaToAcroform
raw.xfaToAcroform(): numberConverts to a plain AcroForm PDF and removes XFA; dynamic forms are laid out into new pages and scripts run first. Text fields keep their formatted display value as /V. Returns the number of AcroForm fields.
On WasmDocument · module forms · C nexpdf_xfa_to_acroform
xfaFlatten
raw.xfaFlatten(): numberConverts and flattens the XFA form: a plain PDF with the values drawn. Returns the number of flattened widgets.
On WasmDocument · module forms · C nexpdf_xfa_flatten
xfaRemove
raw.xfaRemove(): numberRemoves XFA and keeps the AcroForm fields and pages: 1 removed, 0 no XFA.
On WasmDocument · module forms · C nexpdf_xfa_remove
xfaToAcroformJson
raw.xfaToAcroformJson(options_json?: string | null): stringConverts to AcroForm with options {"scripts":true,"flatten":false} and returns a report: flattened, fields, pages, warnings and validation_errors (som, test, severity, message).
On WasmDocument · module forms · C nexpdf_xfa_to_acroform_json
xfaRunScriptsJson
raw.xfaRunScriptsJson(): stringRuns the initialize, calculate and validate scripts (FormCalc and JavaScript) and stores calculated values in the data: data_changed, warnings, validation_errors.
On WasmDocument · module forms · C nexpdf_xfa_run_scripts_json
Real-time collaboration
syncExportJson
raw.syncExportJson(since_version: number): stringNexPDF Sync: every change (from any client) with a Lamport clock above since_version, as a nexpdf-sync/1 change set.
On WasmDocument · module annotations · C nexpdf_sync_export_json
syncExportLocalJson
raw.syncExportLocalJson(since_version: number): stringNexPDF Sync: only this copy's own changes above since_version (what a client pushes); keep the returned clock for the next call.
On WasmDocument · module annotations · C nexpdf_sync_export_local_json
syncApplyJson
raw.syncApplyJson(changes_json?: string | null): stringNexPDF Sync: applies remote changes, last writer wins per record. Returns ok, clock, applied, ignored, conflicts and errors.
On WasmDocument · module annotations · C nexpdf_sync_apply_json
syncSnapshotJson
raw.syncSnapshotJson(): stringNexPDF Sync: every record with its version, base records and tombstones included.
On WasmDocument · module annotations · C nexpdf_sync_snapshot_json
syncSetClientId
raw.syncSetClientId(client_id?: string | null): numberNexPDF Sync: the client id this copy versions its changes under (1 to 64 characters of [A-Za-z0-9-_.:@]).
On WasmDocument · module annotations · C nexpdf_sync_set_client_id
Page editing
rotatePage
raw.rotatePage(page_index: number, degrees: number): numberRotates a page by a multiple of 90 degrees.
On WasmDocument · module editor · C nexpdf_rotate_page
deletePage
raw.deletePage(page_index: number): numberDeletes a page.
On WasmDocument · module editor · C nexpdf_delete_page
duplicatePage
raw.duplicatePage(page_index: number): numberInserts a copy of a page after it.
On WasmDocument · module editor · C nexpdf_duplicate_page
addBlankPage
raw.addBlankPage(): numberAppends a blank page.
On WasmDocument · module editor · C nexpdf_add_blank_page
reversePages
raw.reversePages(): numberReverses the page order.
On WasmDocument · module editor · C nexpdf_reverse_pages
movePage
raw.movePage(from: number, to: number): numberMoves the page at from to index to.
On WasmDocument · module editor · C nexpdf_move_page
cropPage
raw.cropPage(page_index: number, llx: number, lly: number, urx: number, ury: number): numberSets the crop box of a page (PDF points).
On WasmDocument · module editor · C nexpdf_crop_page
extractPages
raw.extractPages(indices: Uint32Array | number[]): WasmDocumentA new document made of the given pages (split).
On WasmDocument · module editor · C nexpdf_extract_pages
appendDocument
raw.appendDocument(other: WasmDocument): numberAppends the pages of another document (merge).
On WasmDocument · module editor · C nexpdf_append_document
insertImagePages
raw.insertImagePages(index: number, data: Uint8Array | number[]): numberInserts the pictures of a JPEG, PNG or TIFF file as pages before index (clamped; the page count appends). Returns the number of pages added.
On WasmDocument · always available · C nexpdf_insert_image_pages
setPageBackground
raw.setPageBackground(options_json: string | null | undefined, rgb: Uint8Array | number[], width: number, height: number): numberSets a page background: a colour and/or an RGB picture. Options: {"color":"#fbf4e2","fit":"cover|stretch|center","scale":1,"opacity":1,"pages":[]}. Returns the pages changed.
On WasmDocument · module editor · C nexpdf_set_page_background
removePageBackground
raw.removePageBackground(pages_json?: string | null): numberRemoves NexPDF backgrounds from the pages in pages_json ("[0,2]"), or from every page.
On WasmDocument · module editor · C nexpdf_remove_page_background
Content editing
pageContentJson
raw.pageContentJson(page: number): stringThe text lines and images of a page as JSON: id, kind (text or image), text, rect, size, color, font, family, bold, italic. Ids stay valid until the next edit of that page.
On WasmDocument · module editor · C nexpdf_page_content_json
editText
raw.editText(page: number, id?: string | null, change_json?: string | null): numberEdits a text line: {text?, size?, color?, dx?, dy?, family?, bold?, italic?}. Empty text deletes it.
On WasmDocument · module editor · C nexpdf_edit_text
addPageText
raw.addPageText(page: number, json?: string | null): numberAdds editable page text: {text, x, y (baseline), size, color, family, bold, italic}.
On WasmDocument · module editor · C nexpdf_add_page_text
deleteContent
raw.deleteContent(page: number, id?: string | null): numberDeletes a text line or an image of the page content.
On WasmDocument · module editor · C nexpdf_delete_content
transformImage
raw.transformImage(page: number, id: string | null | undefined, llx: number, lly: number, urx: number, ury: number): numberMoves or resizes an image to a rectangle (PDF points).
On WasmDocument · module editor · C nexpdf_transform_image
replaceImage
raw.replaceImage(page: number, id: string | null | undefined, rgb: Uint8Array | number[], width: number, height: number): numberReplaces an image with RGB pixels (width x height x 3 bytes).
On WasmDocument · module editor · C nexpdf_replace_image
editTextBlock
raw.editTextBlock(page_index: number, text: string | null | undefined, color_hex: string | null | undefined, font_size: number, bold: number, italic: number, replace_existing: number, llx: number, lly: number, urx: number, ury: number): numberWrites a text block into a rectangle with colour, size and style, optionally replacing the text already there.
On WasmDocument · module editor · C nexpdf_edit_text_block
Metadata, bookmarks, layers and attachments
metadataJson
raw.metadataJson(): stringThe document information (title, author, subject, keywords, ...) as JSON.
On WasmDocument · always available · C nexpdf_metadata_json
setMetadata
raw.setMetadata(title?: string | null, author?: string | null, subject?: string | null, keywords?: string | null): numberSets the title, author, subject and keywords. Omitted (null) values keep the current one.
On WasmDocument · module editor · C nexpdf_set_metadata
outlinesJson
raw.outlinesJson(): stringThe bookmarks as JSON: [{"title","page","children":[...]}].
On WasmDocument · always available · C nexpdf_outlines_json
setOutlinesJson
raw.setOutlinesJson(json?: string | null): numberReplaces the bookmarks with a JSON tree in the same shape.
On WasmDocument · module editor · C nexpdf_set_outlines_json
pageLabelsJson
raw.pageLabelsJson(): stringPage labels: {"labels":["i","ii","1"],"ranges":[{"start":0,"style":"roman","prefix":"","first":1}]}.
On WasmDocument · always available · C nexpdf_page_labels_json
setPageLabelsJson
raw.setPageLabelsJson(json?: string | null): numberSets the page label ranges ([] removes the labels). Styles: decimal, roman, ROMAN, letters, LETTERS, none.
On WasmDocument · module editor · C nexpdf_set_page_labels_json
layersJson
raw.layersJson(): stringThe optional content groups (layers): [{"num","gen","name","visible","printable"}].
On WasmDocument · always available · C nexpdf_layers_json
setLayerVisible
raw.setLayerVisible(num: number, generation: number, visible: number): numberShows or hides a layer.
On WasmDocument · always available · C nexpdf_set_layer_visible
attachmentsJson
raw.attachmentsJson(): stringThe embedded files: [{"name","description","mime","size","page"}]; page is null for document-level files.
On WasmDocument · always available · C nexpdf_attachments_json
attachmentData
raw.attachmentData(name?: string | null): Uint8ArrayThe bytes of an embedded file.
On WasmDocument · always available · C nexpdf_attachment_data
addAttachment
raw.addAttachment(name: string | null | undefined, data: Uint8Array | number[], mime?: string | null, description?: string | null): numberEmbeds a file at document level.
On WasmDocument · module editor · C nexpdf_add_attachment
removeAttachment
raw.removeAttachment(name?: string | null): numberRemoves an embedded file.
On WasmDocument · module editor · C nexpdf_remove_attachment
Encryption, watermarks and stamping
encryptAes256
raw.encryptAes256(user_pw?: string | null, owner_pw?: string | null): numberEncrypts with AES-256 using a user (open) password and an owner password.
On WasmDocument · module security · C nexpdf_encrypt_aes256
encryptWithPermissions
raw.encryptWithPermissions(user_pw: string | null | undefined, owner_pw: string | null | undefined, permissions: number): numberEncrypts with AES-256 and a permission mask: print 1, modify 2, copy 4, annotate 8, fill forms 16, assemble 32.
On WasmDocument · module security · C nexpdf_encrypt_with_permissions
securityJson
raw.securityJson(): stringThe encryption state: {"encrypted","revision","owner","print","modify","copy","annotate","fill_forms","assemble"}.
On WasmDocument · always available · C nexpdf_security_json
removePassword
raw.removePassword(password?: string | null): numberRemoves the protection. Needs owner access: the document was opened with the owner password, or pass it here.
On WasmDocument · module security · C nexpdf_remove_password
addWatermark
raw.addWatermark(text?: string | null): numberStamps a text watermark on every page.
On WasmDocument · module security · C nexpdf_add_watermark
removeWatermarks
raw.removeWatermarks(): numberRemoves the watermarks NexPDF added.
On WasmDocument · module security · C nexpdf_remove_watermarks
addHeaderFooter
raw.addHeaderFooter(header: string | null | undefined, footer: string | null | undefined, font_size: number): numberAdds a header and/or footer to every page. {page} and {total} are replaced; a font size of 0 or less uses the default.
On WasmDocument · module security · C nexpdf_add_header_footer
addBates
raw.addBates(prefix: string | null | undefined, start: number, digits: number): numberAdds Bates numbering: prefix, first number and number of digits.
On WasmDocument · module security · C nexpdf_add_bates
Redaction
applyRedaction
raw.applyRedaction(page_index: number, llx: number, lly: number, urx: number, ury: number, fill_white: number): numberPermanently removes the text, images and annotations under a rectangle and paints an opaque box over it, black or white.
On WasmDocument · module redaction · C nexpdf_apply_redaction
redactMatches
raw.redactMatches(query: string | null | undefined, mode: number, fill_white: number): numberFinds and permanently redacts every match. mode: 0 = text, 1 = regular expression, 2 = pattern id (email, phone, credit-card, iban, pt-nif, us-ssn, ipv4, url, date). Returns the number of areas redacted.
On WasmDocument · module redaction · C nexpdf_redact_matches
Digital signatures
signPades
raw.signPades(signer?: string | null, reason?: string | null, location?: string | null): Uint8ArraySigns with a new self-signed test certificate (PAdES B-B) and returns the signed file. Write the bytes as they are: saving the document again breaks the signature.
On WasmDocument · module signatures · C nexpdf_sign_pades
signPkcs12
raw.signPkcs12(p12: Uint8Array | number[], password?: string | null, options_json?: string | null): Uint8ArraySigns with a PKCS#12 (.p12/.pfx) identity and returns the signed file. Options: {"name","reason","location","contact","field","tsa_url","ltv":true,"appearance":{"page":0,"rect":[llx,lly,urx,ury],"ink":"x,y;x,y|...","text":"..."}}. Without a .p12 a self-signed certificate is created.
On WasmDocument · module signatures · C nexpdf_sign_pkcs12
prepareExternalSignature
raw.prepareExternalSignature(cert: Uint8Array | number[], options_json?: string | null): Uint8ArrayExternal signing (HSM, smart card, cloud KMS), step 1: a PDF with an empty signature for the signer certificate (PEM or DER, optionally followed by its chain). Options as for PKCS#12 signing.
On WasmDocument · module signatures · C nexpdf_prepare_external_signature
addDocumentTimestamp
raw.addDocumentTimestamp(options_json?: string | null): Uint8ArrayAdds an RFC 3161 document timestamp from a TSA (PAdES B-LTA). Options: {"tsa_url" (required),"hash","field","reserved","ltv"}; with ltv the validation data of earlier signatures goes into the DSS first. Returns the new file.
On WasmDocument · module signatures · C nexpdf_add_document_timestamp
prepareDocumentTimestamp
raw.prepareDocumentTimestamp(options_json?: string | null): Uint8ArrayDocument timestamp from your own TSA or HSM, step 1: the PDF with an empty timestamp (options as for adding one, without tsa_url).
On WasmDocument · module signatures · C nexpdf_prepare_document_timestamp
PDF/A, PDF/X and PDF/UA
convertPdfa
raw.convertPdfa(): numberConverts the document to PDF/A (ISO 19005) for archiving.
On WasmDocument · module standards · C nexpdf_convert_pdfa
convertPdfx
raw.convertPdfx(): numberConverts the document to PDF/X for print exchange.
On WasmDocument · module standards · C nexpdf_convert_pdfx
autoTag
raw.autoTag(lang: string | null | undefined, force: number): stringTags the document for accessibility (PDF/UA structure tree, language, title, metadata). lang is a BCP 47 tag (default en-US); force re-tags a document that is already tagged. Returns a JSON report.
On WasmDocument · module standards · C nexpdf_auto_tag
validatePdfaJson
raw.validatePdfaJson(level?: string | null): stringRule-based PDF/A validation for 1a to 4f (the declared level, or 2b, when empty): compliant, level and failures with clause, message, page and object.
On WasmDocument · module standards · C nexpdf_validate_pdfa_json
validatePdfuaJson
raw.validatePdfuaJson(): stringPDF/UA validation (PDF/UA-1, or PDF/UA-2 when declared), with the same report as PDF/A validation.
On WasmDocument · module standards · C nexpdf_validate_pdfua_json
convertPdfaLevel
raw.convertPdfaLevel(level?: string | null): numberConverts to a chosen PDF/A level (2b when empty); level A tags the document first. 1 when the result validates; otherwise the error lists the clauses still failing.
On WasmDocument · module standards · C nexpdf_convert_pdfa_level
convertPdfaJson
raw.convertPdfaJson(level: string | null | undefined, flatten_dpi: number, substitute_fonts: number): stringConverts to a PDF/A level (1a to 4f, 2b when empty) and returns the report: level, compliant, fixed, substitutions and remaining. flatten_dpi is the resolution PDF/A-1 transparency is flattened at (300 when 0 or less); substitute_fonts 0 leaves non-embedded fonts alone.
On WasmDocument · module standards · C nexpdf_convert_pdfa_json
convertPdfuaJson
raw.convertPdfuaJson(part: number, lang?: string | null): stringConverts to PDF/UA-1 or PDF/UA-2 (part 1 or 2): tags an untagged document, embeds fonts and, for part 2, uses the PDF 2.0 namespaces. lang (en-US when empty) applies when the document has none. Returns profile, compliant, fixed, warnings, substitutions, remaining.
On WasmDocument · module standards · C nexpdf_convert_pdfua_json
validatePdfuaPartJson
raw.validatePdfuaPartJson(part: number): stringValidates against PDF/UA-1 or PDF/UA-2 (part 1 or 2) whatever the document declares, with the same report as PDF/UA validation.
On WasmDocument · module standards · C nexpdf_validate_pdfua_part_json
OCR
ocr
raw.ocr(options_json?: string | null): stringRecognises scanned pages and adds an invisible, searchable text layer. Options (may be omitted): {"engine":"auto|builtin|tesseract|neural","languages":"por+eng","dpi":300,"pages":[0],"force":false}. Returns a JSON report.
On WasmDocument · module ocr · C nexpdf_ocr
Compare, optimise and memory
compareJson
raw.compareJson(b: WasmDocument, dpi: number): stringCompares two documents (text and visual differences per page) at the given resolution, as JSON.
On WasmDocument · always available · C nexpdf_compare_json
compareOverlayPng
raw.compareOverlayPng(b: WasmDocument, page_index: number, dpi: number): Uint8ArrayA PNG overlay of the visual differences of one page of two documents.
On WasmDocument · always available · C nexpdf_compare_overlay_png
optimize
raw.optimize(): stringOptimises the document (removes unused objects, recompresses streams); returns a JSON report.
On WasmDocument · module editor · C nexpdf_optimize
subsetFonts
raw.subsetFonts(): stringSubsets the embedded fonts to the glyphs the document uses; returns a JSON report.
On WasmDocument · module editor · C nexpdf_subset_fonts
trimMemory
raw.trimMemory(): numberDrops cached data of the document; returns the bytes freed.
On WasmDocument · always available · C nexpdf_trim_memory
memoryUsageBytes
raw.memoryUsageBytes(): numberApproximate memory used by the document, in bytes.
On WasmDocument · always available · C nexpdf_memory_usage_bytes
compareTextJson
raw.compareTextJson(b: WasmDocument, options_json?: string | null): stringWord-level text comparison of two documents: inserted, deleted, replaced and moved text with positions, and a summary. Options {"ignore_case","ignore_punctuation","detect_moves","min_move_words","align","page_map"}.
On WasmDocument · always available · C nexpdf_compare_text_json
compareAnnotate
raw.compareAnnotate(b: WasmDocument, options_json?: string | null): Uint8ArrayThe word-level comparison as a new PDF with highlight annotations (deleted red, inserted green, moved blue). Options add output, author and the colours.
On WasmDocument · always available · C nexpdf_compare_annotate