Docs / API reference

Markdown

JavaScript API

Everything exported by the `docuverse` package. Errors throw `UdsError`.

Setup

ExportMeaning
init(source?)Loads the engine. In browsers, source can be the URL of uds_pdf.wasm
version()The engine version
registerFont(bytes)Adds a TrueType or OpenType font
createViewer(element, options)From docuverse/viewer: the ready-made viewer (see The viewer)

PdfDocument

MemberMeaning
PdfDocument.open(bytes, password?)A PDF, or a .docx laid out into pages
PdfDocument.create(), PdfDocument.sample()An empty document; a sample document
pageCount, info(), setInfo()Page count and metadata
renderPage(page, scale)RGBA pixels: { width, height, data }
renderPagePng(page, scale)PNG bytes
pageText(page), pageTextLayout(page)Plain text; text lines with their positions
search(query, { caseSensitive })[{ page, text, quadPoints }]
textBlocks(page)The page’s text in blocks (paragraphs, headings, table cells) with runs of font, size and colour
replaceText(page, block, text), editText(page, spec)Edit the page’s own text: replace a block (keeping its style), set styled runs, add or remove text; one undo step
textEditFonts(page, spec)Fonts an edit needs that are not loaded yet
pageImages(page)The page’s own pictures with their place: { images: [{ id, rect, matrix, width, height }] }
transformImage(page, id, t), replaceImage(page, id, bytes), deleteImage(page, id), addImage(page, bytes, rect?)Move, resize or turn a picture, put another one in its place, take it off, or add a PNG or JPEG; one undo step
pageTables(page), setTable(page, id, spec), deleteTable(page, id)Tables drawn on the page: { x, top, cols, rows, border, borderWidth, pad, cells: [[{ paragraphs, align, fill }]] }; rows grow to hold their text; editable again after saving
insertBlankPage(), deletePage(), movePage(), rotatePage(), appendPdf(bytes)Page tools
annotations(page?), annotation(id)Read annotations
addAnnotation(page, spec), updateAnnotation(id, patch), deleteAnnotation(id)Change annotations
moveAnnotation(), reorderAnnotation(), flatten()Position, stacking order, flatten into the page
exportAnnotations(), importAnnotations(list)Annotations as JSON
renderAnnotationPng(id, scale)One annotation alone as a PNG
undo(), redo()History
save({ incremental }), close()Bytes out; free the document
setLicenseKey(key, { host, app, licenseServer }), licenseStatus(), licenseCheck()Your licence key (checked offline). Without a key nothing opens (UdsError with code LICENSE_KEY_NEEDED); a trial key works with a watermark. A key is for one SDK: a Web SDK key here in Node.js (or a Server SDK key in a browser) throws UdsError with code LICENSE_WRONG_SDK

Interactive editor

For your own screen: setTool(name), setStyle(obj), getStyle(), pointer(kind, page, scale, x, y, mods), key(name), editorRender(page, scale), editorRenderRegion(page, scale, x, y, w, h, layer) (only the annotations of part of a page, on a transparent background), selected(), select(id), setEditing(id).

WordDocument

MemberMeaning
WordDocument.isWord(bytes), WordDocument.open(bytes)Check and open a .docx
command({ cmd, … })Edit; returns the new state (see Word documents)
insertImage(bytes, { width, height })Add a picture at the caret
missingFonts(), relayout()Fonts the document needs; lay out again
pdf(), save(), close()The pages as PDF; the .docx; free

ExcelDocument

MemberMeaning
ExcelDocument.isExcel(bytes), ExcelDocument.open(bytes), ExcelDocument.create()Check, open or create a workbook
command({ cmd, … })Edit; returns the new state (see Excel workbooks)
render(sheet, x, y, width, height, scale)Draw part of a sheet
missingFonts(), relayout()Fonts the workbook needs; measure again
save(), pdf({ all, view }), close()The .xlsx; print to PDF (view: true: the sheet pages annotations are kept on); free