API reference
Every class, method and function of the NexPDF Python 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 (import nexpdf). It lists 195 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.
Setup and lifecycle
from_bytes
Document.from_bytes(data: bytes, password: Optional[str] = None) -> "Document"Opens a PDF (or a JPEG/PNG/TIFF picture) from bytes; Word, Excel and PowerPoint files, EPUB / FictionBook / XPS books and CBZ comics are converted. password opens encrypted files.
On Document
open
Document.open(path: PathLike, password: Optional[str] = None) -> "Document"Opens a file; see from_bytes.
On Document
close
doc.close() -> NoneFrees the native document; later calls raise ValueError.
On Document
closed
doc.closed: boolOn Document
save
doc.save(path: PathLike, linearized: bool = False) -> NoneWrites the document (linearized = "Fast Web View").
On Document
copy
doc.copy() -> "Document"An independent copy (for undo snapshots or work on another thread).
On Document
page_size
doc.page_size(page_index: int) -> tuple[float, float]Displayed page size in points (crop box, /Rotate and /UserUnit applied).
On Document
version
nexpdf.version() -> strThe engine version.
On nexpdf
activate_license
nexpdf.activate_license(key_or_xml: str, platform: str = "server", app_id: str = "") -> intActivates a license key or license.xml once per process. Returns 2 (licensed) or 1 (trial); raises LicenseError otherwise. Without a license the SDK is view-only and renders carry a watermark.
On nexpdf
license_status
nexpdf.license_status() -> dict{"licensed", "trial", "licensee", "modules", "expires", ...} as a dict.
On nexpdf
is_licensed
nexpdf.is_licensed(module: str) -> boolThe license unlocks module (annotations, forms, editor, security, redaction, signatures, conversion, ocr, standards).
On nexpdf
loads
nexpdf.loads(result: str) -> AnyParses a JSON result of a ..._json method.
On nexpdf
load_library
nexpdf.load_library(path: Optional[str] = None) -> ctypes.CDLLLoads libnexpdf_ffi. Called automatically on first use; call it first to pick a file. Search order: path, $NEXPDF_LIB_PATH (a file), $NEXPDF_LIB_DIR (a folder), nexpdf/lib/ inside the package, the repository's target/release and target/debug, then the system loader.
On nexpdf
last_error
nexpdf.last_error() -> Optional[str]The last error on this thread, or None.
On nexpdf
Library and licensing
license_status_json
nexpdf.license_status_json() -> strThe active license as JSON: state (unlicensed, trial or licensed), licensee, id, tier, modules, expires_at, days_left and watermark.
On nexpdf · always available · C nexpdf_license_status_json
invoke
nexpdf.invoke(request_json: Optional[str] = None) -> strThe whole API behind one JSON call, for bridges that only pass strings: {"fn":"to_xlsx","args":[handle]} returns {"ok":true,"result":...} or {"ok":false,"error":"..."}. Documents are handle numbers and byte buffers base64.
On nexpdf · always available · C nexpdf_invoke
register_standard_font
nexpdf.register_standard_font(data: bytes) -> intRegisters a Helvetica, Times or Courier compatible TrueType font (for example Liberation) used for non-embedded standard fonts and PDF/A. Needed only by builds without bundled fonts. 1 on success, 0 if the font is not such a font.
On nexpdf · always available · C nexpdf_register_standard_font
has_bundled_fonts
nexpdf.has_bundled_fonts() -> int1 when the Liberation fonts are compiled in, 0 in the lighter builds.
On nexpdf · always available · C nexpdf_has_bundled_fonts
Opening and saving
open_bytes_with_password
nexpdf.open_bytes_with_password(data: bytes, password: Optional[str] = None) -> "Document"Opens an encrypted PDF with its user or owner password (RC4, AES-128, AES-256). Fails with "password required" or "incorrect password" when the password is the problem.
On nexpdf · always available · C nexpdf_open_bytes_with_password
from_html
nexpdf.from_html(html: Optional[str] = None) -> "Document"Lays out HTML as a new PDF document.
On nexpdf · module conversion · C nexpdf_from_html
open_office
nexpdf.open_office(data: bytes) -> "Document"Converts Word, Excel or PowerPoint bytes (format detected) to a new PDF document.
On nexpdf · module conversion · C nexpdf_open_office
open_ebook
nexpdf.open_ebook(data: bytes) -> "Document"Converts EPUB, FictionBook (.fb2, .fb2.zip), XPS/OpenXPS or a CBZ comic archive to a new PDF document.
On nexpdf · module conversion · C nexpdf_open_ebook
open_image
nexpdf.open_image(data: bytes) -> "Document"Converts JPEG, PNG or TIFF bytes to a new PDF, one page per picture.
On nexpdf · always available · C nexpdf_open_image
save_bytes
doc.save_bytes() -> bytesThe document, with every change, as PDF bytes (full rewrite).
On Document · always available · C nexpdf_save_bytes
save_linearized
doc.save_linearized() -> bytesA linearized ("Fast Web View") PDF: the first page shows before the download ends.
On Document · always available · C nexpdf_save_linearized
Pages and rendering
page_count
doc.page_count() -> intNumber of pages.
On Document · always available · C nexpdf_page_count
page_width
doc.page_width(page_index: int) -> floatDisplayed page width in points (crop box, rotation and /UserUnit applied).
On Document · always available · C nexpdf_page_width
page_height
doc.page_height(page_index: int) -> floatDisplayed page height in points (crop box, rotation and /UserUnit applied).
On Document · always available · C nexpdf_page_height
page_view_json
doc.page_view_json(page_index: int) -> strHow the page is displayed: width, height, rotation, user_unit, crop and the PDF-to-display matrix to_display.
On Document · always available · C nexpdf_page_view_json
render_page_png
doc.render_page_png(page_index: int, dpi: float) -> bytesRenders a page to PNG at the given resolution (dots per inch). Unlicensed and trial renders carry a watermark.
On Document · always available · C nexpdf_render_page_png
render_thumb_png
doc.render_thumb_png(page_index: int, max_dim: int) -> bytesRenders a thumbnail PNG whose longer side is at most max_dim pixels.
On Document · always available · C nexpdf_render_thumb_png
set_overprint
doc.set_overprint(mode: int) -> intOverprint simulation for later renders: 0 = PDF/X documents only (default), 1 = always, 2 = never.
On Document · always available · C nexpdf_set_overprint
Text, search and assistant
extract_page_text
doc.extract_page_text(page_index: int) -> strThe text of a page in reading order.
On Document · always available · C nexpdf_extract_page_text
extract_markdown
doc.extract_markdown() -> strThe whole document as Markdown (headings, lists, tables).
On Document · always available · C nexpdf_extract_markdown
search_json
doc.search_json(query: Optional[str] = None) -> strFinds 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 Document · always available · C nexpdf_search_json
page_blocks_json
doc.page_blocks_json(page_index: int) -> strThe text blocks of a page as JSON: text, font size and the rectangle llx, lly, urx, ury.
On Document · always available · C nexpdf_page_blocks_json
ask_document
doc.ask_document(question: Optional[str], k: int, max_chars: int) -> strDocument 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 Document · always available · C nexpdf_ask_document
page_words_json
doc.page_words_json(page_index: int, options_json: Optional[str] = None) -> strThe 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 Document · always available · C nexpdf_page_words_json
Conversion
to_html
doc.to_html() -> strThe document as HTML.
On Document · module conversion · C nexpdf_to_html
to_json
doc.to_json() -> strThe document content as JSON.
On Document · module conversion · C nexpdf_to_json
to_xml
doc.to_xml() -> strThe document content as XML.
On Document · module conversion · C nexpdf_to_xml
to_csv
doc.to_csv() -> strTables of the document as CSV.
On Document · module conversion · C nexpdf_to_csv
to_rtf
doc.to_rtf() -> strThe document as RTF.
On Document · module conversion · C nexpdf_to_rtf
to_docx
doc.to_docx() -> bytesThe document as a Word (.docx) file.
On Document · module conversion · C nexpdf_to_docx
to_xlsx
doc.to_xlsx() -> bytesThe document as an Excel workbook, one sheet per page.
On Document · module conversion · C nexpdf_to_xlsx
to_pptx
doc.to_pptx() -> bytesThe document as a PowerPoint presentation, one slide per page.
On Document · module conversion · C nexpdf_to_pptx
to_reflow_html
doc.to_reflow_html(options_json: Optional[str] = None) -> strThe text as responsive HTML for small screens. Options (may be omitted): {"pages":[0],"images":true,"full_page":true,"title":"..."}.
On Document · module conversion · C nexpdf_to_reflow_html
open_xlsx_with_clock
nexpdf.open_xlsx_with_clock(data: bytes, clock_unix_seconds: float) -> "Document"Converts an Excel workbook with a fixed clock: NOW() and TODAY() in formulas without a cached value return the given Unix time (seconds, no time zone applied).
On nexpdf · module conversion · C nexpdf_open_xlsx_with_clock
open_docx_with_options_json
nexpdf.open_docx_with_options_json(data: bytes, options_json: Optional[str] = None) -> "Document"Converts a Word document with options {"show_comments":false,"show_revisions":false}: comments in balloons in a markup area, and tracked changes drawn as markup instead of the final document.
On nexpdf · module conversion · C nexpdf_open_docx_with_options_json
Templates
template_docx_to_pdf
nexpdf.template_docx_to_pdf(template_bytes: bytes, data_json: Optional[str] = None, options_json: Optional[str] = None) -> "Document"Fills a Word template with JSON data and converts it to a new PDF document. Options: {"strict":false,"locale":"en"}; with strict a missing field fails the call.
On nexpdf · module conversion · C nexpdf_template_docx_to_pdf
template_docx_fill
nexpdf.template_docx_fill(template_bytes: bytes, data_json: Optional[str] = None) -> bytesFills a Word template with JSON data and returns the new .docx bytes.
On nexpdf · module conversion · C nexpdf_template_docx_fill
template_html_to_pdf
nexpdf.template_html_to_pdf(html_utf8: Optional[str] = None, data_json: Optional[str] = None, options_json: Optional[str] = None) -> "Document"Fills an HTML template with JSON data (values HTML-escaped, {{{raw}}} not) and lays it out as a new PDF document.
On nexpdf · module conversion · C nexpdf_template_html_to_pdf
template_fill_pdf
doc.template_fill_pdf(data_json: Optional[str] = None, options_json: Optional[str] = None) -> intFills 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 Document · module conversion · C nexpdf_template_fill_pdf
template_docx_fill_with
nexpdf.template_docx_fill_with(template_bytes: bytes, data_json: Optional[str] = None, options_json: Optional[str] = None) -> bytesFills a Word template with JSON data and options {"strict","locale"}, and returns the new .docx bytes.
On nexpdf · module conversion · C nexpdf_template_docx_fill_with
Office editing
xlsx_edit
nexpdf.xlsx_edit(data: bytes, edits_json: Optional[str] = None) -> bytesSets cells of an Excel workbook (numbers, text, booleans, formulas, or null to clear), recalculates every formula and the charts, and returns the new .xlsx bytes. JSON {"sheet","edits":[{"cell","value"}],"ranges":[{"start","rows"}],"recalculate"}.
On nexpdf · module conversion · C nexpdf_xlsx_edit
xlsx_cells_json
nexpdf.xlsx_cells_json(data: bytes, options_json: Optional[str] = None) -> strThe cells of an Excel workbook as JSON: per sheet, each cell with its type, value and formula. Options {"sheet","range","recalculate"}.
On nexpdf · module conversion · C nexpdf_xlsx_cells_json
docx_edit
nexpdf.docx_edit(data: bytes, ops_json: Optional[str] = None) -> bytesApplies operations to a Word document and returns the new .docx bytes: replace (across runs, headers and footers), set_text, insert and delete paragraphs.
On nexpdf · module conversion · C nexpdf_docx_edit
docx_paragraphs_json
nexpdf.docx_paragraphs_json(data: bytes) -> strThe paragraphs of a Word document as JSON: index, style, text and whether each is in a table.
On nexpdf · module conversion · C nexpdf_docx_paragraphs_json
Structured extraction and barcodes
extract_tables_json
doc.extract_tables_json(page_index: int, options_json: Optional[str] = None) -> strRuled 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 Document · module conversion · C nexpdf_extract_tables_json
extract_key_values_json
doc.extract_key_values_json(options_json: Optional[str] = None) -> strLabel/value pairs from the layout and typed entities (dates, amounts, IBANs, e-mails, phones, VAT numbers) with normalised values. Options {"pages","date_order"}.
On Document · module conversion · C nexpdf_extract_key_values_json
extraction_prompt_json
doc.extraction_prompt_json(schema_json: Optional[str] = None, options_json: Optional[str] = None) -> strA prompt (system, prompt, response_schema) for extracting a JSON schema with the language model of your choice. The engine makes no network calls.
On Document · module conversion · C nexpdf_extraction_prompt_json
extraction_validate_json
doc.extraction_validate_json(schema_json: Optional[str] = None, answer_json: Optional[str] = None) -> strValidates and coerces a model answer against the schema and grounds each value on the pages: valid, value, errors, warnings, fields.
On Document · module conversion · C nexpdf_extraction_validate_json
classify_document_json
doc.classify_document_json(labels_json: Optional[str] = None) -> strClassifies the document into one of the given labels by keywords, with scores and a prompt for LLM classification.
On Document · module conversion · C nexpdf_classify_document_json
read_barcodes_json
doc.read_barcodes_json(page_index: int, options_json: Optional[str] = None) -> strReads 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 Document · module conversion · C nexpdf_read_barcodes_json
read_barcodes_image_json
nexpdf.read_barcodes_image_json(data: bytes, options_json: Optional[str] = None) -> strReads the barcodes of a PNG or JPEG image, with positions in pixels.
On nexpdf · module conversion · C nexpdf_read_barcodes_image_json
add_barcode
doc.add_barcode(page_index: int, llx: float, lly: float, urx: float, ury: float, format_: Optional[str] = None, text: Optional[str] = None) -> intDraws text as a vector barcode (white background, quiet zone) into a rectangle of a page, in PDF points.
On Document · module editor · C nexpdf_add_barcode
add_barcode_ex
doc.add_barcode_ex(page_index: int, llx: float, lly: float, urx: float, ury: float, format_: Optional[str] = None, text: Optional[str] = None, options_json: Optional[str] = None) -> intDraws a vector barcode with options {"human_readable":"auto"|"always"|"never","quiet_zone","background","color"}; auto prints the digits under EAN and UPC codes.
On Document · module editor · C nexpdf_add_barcode_ex
Annotations
add_annotation
doc.add_annotation(page_index: int, kind: Optional[str], color_hex: Optional[str], opacity: float, contents: Optional[str], llx: float, lly: float, urx: float, ury: float) -> intAdds 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 Document · module annotations · C nexpdf_add_annotation
add_ink
doc.add_ink(page_index: int, color_hex: Optional[str], stroke_width: float, opacity: float, coords: Optional[str] = None) -> intAdds a freehand ink annotation. coords is "x,y;x,y;..." in PDF points.
On Document · module annotations · C nexpdf_add_ink
add_line
doc.add_line(page_index: int, kind: Optional[str], color_hex: Optional[str], opacity: float, stroke_width: float, x1: float, y1: float, x2: float, y2: float) -> intAdds a line or arrow (kind is Line or Arrow) from (x1, y1) to (x2, y2) in PDF points.
On Document · module annotations · C nexpdf_add_line
annotations_json
doc.annotations_json(page_index: int) -> strThe annotations of a page as JSON: num, gen, kind, color, contents and the rectangle.
On Document · always available · C nexpdf_annotations_json
remove_annotation
doc.remove_annotation(page_index: int, num: int, generation: int) -> intRemoves the annotation with object number num and generation gen from a page.
On Document · module annotations · C nexpdf_remove_annotation
move_annotation
doc.move_annotation(num: int, generation: int, dx: float, dy: float) -> intMoves an annotation by (dx, dy) PDF points.
On Document · module annotations · C nexpdf_move_annotation
set_annotation_contents
doc.set_annotation_contents(num: int, generation: int, contents: Optional[str] = None) -> intReplaces the text contents of an annotation.
On Document · module annotations · C nexpdf_set_annotation_contents
export_xfdf
doc.export_xfdf() -> strExports every annotation as an XFDF document.
On Document · module annotations · C nexpdf_export_xfdf
import_xfdf
doc.import_xfdf(xfdf: Optional[str] = None) -> intImports annotations from an XFDF document.
On Document · module annotations · C nexpdf_import_xfdf
flatten_annotations
doc.flatten_annotations(page_index: int) -> intBurns annotations into the page content. A negative page index flattens every page.
On Document · module annotations · C nexpdf_flatten_annotations
add_image_stamp
doc.add_image_stamp(page: int, llx: float, lly: float, urx: float, ury: float, rgba: bytes, width: int, height: int, opacity: float) -> intAdds a picture stamp annotation from RGBA pixels (transparency kept). 1 on success.
On Document · module annotations · C nexpdf_add_image_stamp
add_measurement
doc.add_measurement(page: int, json: Optional[str] = None) -> strStores 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 Document · module annotations · C nexpdf_add_measurement
measurements_json
doc.measurements_json() -> strThe stored measurements as JSON.
On Document · always available · C nexpdf_measurements_json
add_file_attachment_annot
doc.add_file_attachment_annot(page_index: int, x: float, y: float, name: Optional[str], data: bytes, mime: Optional[str] = None, description: Optional[str] = None) -> intAdds a paperclip annotation carrying a file; (x, y) is the top-left corner of the icon in PDF points.
On Document · module annotations · C nexpdf_add_file_attachment_annot
add_ink_signature
doc.add_ink_signature(page_index: int, color_hex: Optional[str], stroke_width: float, strokes: Optional[str] = None) -> intAdds 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 Document · module annotations · C nexpdf_add_ink_signature
reply_to_annotation
doc.reply_to_annotation(page_index: int, num: int, generation: int, author: Optional[str] = None, text: Optional[str] = None) -> intAdds a reply by author to an annotation (or to another reply). Returns the reply object number (generation 0).
On Document · module annotations · C nexpdf_reply_to_annotation
annotation_replies_json
doc.annotation_replies_json(page_index: int, num: int, generation: int) -> strThe thread under an annotation, oldest first: num, gen, in_reply_to, author, date, text, state, state_model.
On Document · module annotations · C nexpdf_annotation_replies_json
set_annotation_state
doc.set_annotation_state(page_index: int, num: int, generation: int, author: Optional[str] = None, state: Optional[str] = None) -> intSets a review state (Accepted, Rejected, Cancelled, Completed, None) or marked state (Marked, Unmarked) as a hidden state reply. Returns its object number.
On Document · module annotations · C nexpdf_set_annotation_state
Forms
form_fields_json
doc.form_fields_json() -> strThe form fields as JSON: name, kind, value, page, rectangle, read_only and required.
On Document · module forms · C nexpdf_form_fields_json
fill_form_field
doc.fill_form_field(name: Optional[str] = None, value: Optional[str] = None) -> intSets 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 Document · module forms · C nexpdf_fill_form_field
set_signature_appearance
doc.set_signature_appearance(name: Optional[str], rgba: bytes, width: int, height: int) -> intShows 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 Document · module forms · C nexpdf_set_signature_appearance
add_form_field
doc.add_form_field(page_index: int, kind: Optional[str], name: Optional[str], llx: float, lly: float, urx: float, ury: float) -> intAdds a form field named name in a rectangle of a page. kind: text (default), checkbox, radio, combobox, listbox, button, signature or barcode.
On Document · module forms · C nexpdf_add_form_field
flatten_forms
doc.flatten_forms() -> intBurns the form fields into the page content.
On Document · module forms · C nexpdf_flatten_forms
recalculate_forms
doc.recalculate_forms() -> intRuns every calculate script; returns how many fields changed.
On Document · module forms · C nexpdf_recalculate_forms
export_form_json
doc.export_form_json() -> strThe field values as a JSON object.
On Document · module forms · C nexpdf_export_form_json
import_form_json
doc.import_form_json(json: Optional[str] = None) -> intFills fields from a JSON object of names and values.
On Document · module forms · C nexpdf_import_form_json
export_form_fdf
doc.export_form_fdf(pdf_name: Optional[str] = None) -> bytesThe field values as an FDF file; pdf_name is the file name recorded in it.
On Document · module forms · C nexpdf_export_form_fdf
import_form_fdf
doc.import_form_fdf(data: bytes) -> intFills fields from an FDF file.
On Document · module forms · C nexpdf_import_form_fdf
export_form_xfdf
doc.export_form_xfdf(pdf_name: Optional[str] = None) -> strThe field values as XFDF.
On Document · module forms · C nexpdf_export_form_xfdf
import_form_xfdf
doc.import_form_xfdf(xfdf: Optional[str] = None) -> intFills fields from XFDF.
On Document · module forms · C nexpdf_import_form_xfdf
XFA forms
xfa_info_json
doc.xfa_info_json() -> strWhether the document has XFA, whether it is dynamic, field and data counts and the XDP packets.
On Document · module forms · C nexpdf_xfa_info_json
xfa_export_data
doc.xfa_export_data(format_: Optional[str] = None) -> strThe XFA data as xml (default) or flat json ({"path":"value"}). Fails when the document has no XFA.
On Document · module forms · C nexpdf_xfa_export_data
xfa_import_data
doc.xfa_import_data(data: Optional[str] = None, format_: Optional[str] = None) -> intImports 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 Document · module forms · C nexpdf_xfa_import_data
xfa_to_acroform
doc.xfa_to_acroform() -> intConverts 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 Document · module forms · C nexpdf_xfa_to_acroform
xfa_flatten
doc.xfa_flatten() -> intConverts and flattens the XFA form: a plain PDF with the values drawn. Returns the number of flattened widgets.
On Document · module forms · C nexpdf_xfa_flatten
xfa_remove
doc.xfa_remove() -> intRemoves XFA and keeps the AcroForm fields and pages: 1 removed, 0 no XFA.
On Document · module forms · C nexpdf_xfa_remove
xfa_to_acroform_json
doc.xfa_to_acroform_json(options_json: Optional[str] = None) -> strConverts to AcroForm with options {"scripts":true,"flatten":false} and returns a report: flattened, fields, pages, warnings and validation_errors (som, test, severity, message).
On Document · module forms · C nexpdf_xfa_to_acroform_json
xfa_run_scripts_json
doc.xfa_run_scripts_json() -> strRuns the initialize, calculate and validate scripts (FormCalc and JavaScript) and stores calculated values in the data: data_changed, warnings, validation_errors.
On Document · module forms · C nexpdf_xfa_run_scripts_json
register_fallback_font
nexpdf.register_fallback_font(data: bytes) -> intRegisters a TrueType/OpenType font (or .ttc) for text the bundled fonts cannot show (CJK, Arabic and more) when XFA forms are laid out; the data is copied. 1, or -1.
On nexpdf · module forms · C nexpdf_register_fallback_font
Real-time collaboration
sync_export_json
doc.sync_export_json(since_version: int) -> strNexPDF Sync: every change (from any client) with a Lamport clock above since_version, as a nexpdf-sync/1 change set.
On Document · module annotations · C nexpdf_sync_export_json
sync_export_local_json
doc.sync_export_local_json(since_version: int) -> strNexPDF Sync: only this copy's own changes above since_version (what a client pushes); keep the returned clock for the next call.
On Document · module annotations · C nexpdf_sync_export_local_json
sync_apply_json
doc.sync_apply_json(changes_json: Optional[str] = None) -> strNexPDF Sync: applies remote changes, last writer wins per record. Returns ok, clock, applied, ignored, conflicts and errors.
On Document · module annotations · C nexpdf_sync_apply_json
sync_snapshot_json
doc.sync_snapshot_json() -> strNexPDF Sync: every record with its version, base records and tombstones included.
On Document · module annotations · C nexpdf_sync_snapshot_json
sync_set_client_id
doc.sync_set_client_id(client_id: Optional[str] = None) -> intNexPDF Sync: the client id this copy versions its changes under (1 to 64 characters of [A-Za-z0-9-_.:@]).
On Document · module annotations · C nexpdf_sync_set_client_id
Page editing
rotate_page
doc.rotate_page(page_index: int, degrees: int) -> intRotates a page by a multiple of 90 degrees.
On Document · module editor · C nexpdf_rotate_page
delete_page
doc.delete_page(page_index: int) -> intDeletes a page.
On Document · module editor · C nexpdf_delete_page
duplicate_page
doc.duplicate_page(page_index: int) -> intInserts a copy of a page after it.
On Document · module editor · C nexpdf_duplicate_page
add_blank_page
doc.add_blank_page() -> intAppends a blank page.
On Document · module editor · C nexpdf_add_blank_page
reverse_pages
doc.reverse_pages() -> intReverses the page order.
On Document · module editor · C nexpdf_reverse_pages
move_page
doc.move_page(from_: int, to: int) -> intMoves the page at from to index to.
On Document · module editor · C nexpdf_move_page
crop_page
doc.crop_page(page_index: int, llx: float, lly: float, urx: float, ury: float) -> intSets the crop box of a page (PDF points).
On Document · module editor · C nexpdf_crop_page
extract_pages
doc.extract_pages(indices: Sequence[int]) -> "Document"A new document made of the given pages (split).
On Document · module editor · C nexpdf_extract_pages
append_document
doc.append_document(other: "Document") -> intAppends the pages of another document (merge).
On Document · module editor · C nexpdf_append_document
insert_image_pages
doc.insert_image_pages(index: int, data: bytes) -> intInserts 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 Document · always available · C nexpdf_insert_image_pages
set_page_background
doc.set_page_background(options_json: Optional[str], rgb: bytes, width: int, height: int) -> intSets 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 Document · module editor · C nexpdf_set_page_background
remove_page_background
doc.remove_page_background(pages_json: Optional[str] = None) -> intRemoves NexPDF backgrounds from the pages in pages_json ("[0,2]"), or from every page.
On Document · module editor · C nexpdf_remove_page_background
Content editing
page_content_json
doc.page_content_json(page: int) -> strThe 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 Document · module editor · C nexpdf_page_content_json
edit_text
doc.edit_text(page: int, id_: Optional[str] = None, change_json: Optional[str] = None) -> intEdits a text line: {text?, size?, color?, dx?, dy?, family?, bold?, italic?}. Empty text deletes it.
On Document · module editor · C nexpdf_edit_text
add_page_text
doc.add_page_text(page: int, json: Optional[str] = None) -> intAdds editable page text: {text, x, y (baseline), size, color, family, bold, italic}.
On Document · module editor · C nexpdf_add_page_text
delete_content
doc.delete_content(page: int, id_: Optional[str] = None) -> intDeletes a text line or an image of the page content.
On Document · module editor · C nexpdf_delete_content
transform_image
doc.transform_image(page: int, id_: Optional[str], llx: float, lly: float, urx: float, ury: float) -> intMoves or resizes an image to a rectangle (PDF points).
On Document · module editor · C nexpdf_transform_image
replace_image
doc.replace_image(page: int, id_: Optional[str], rgb: bytes, width: int, height: int) -> intReplaces an image with RGB pixels (width x height x 3 bytes).
On Document · module editor · C nexpdf_replace_image
edit_text_block
doc.edit_text_block(page_index: int, text: Optional[str], color_hex: Optional[str], font_size: float, bold: int, italic: int, replace_existing: int, llx: float, lly: float, urx: float, ury: float) -> intWrites a text block into a rectangle with colour, size and style, optionally replacing the text already there.
On Document · module editor · C nexpdf_edit_text_block
Metadata, bookmarks, layers and attachments
metadata_json
doc.metadata_json() -> strThe document information (title, author, subject, keywords, ...) as JSON.
On Document · always available · C nexpdf_metadata_json
set_metadata
doc.set_metadata(title: Optional[str] = None, author: Optional[str] = None, subject: Optional[str] = None, keywords: Optional[str] = None) -> intSets the title, author, subject and keywords. Omitted (null) values keep the current one.
On Document · module editor · C nexpdf_set_metadata
outlines_json
doc.outlines_json() -> strThe bookmarks as JSON: [{"title","page","children":[...]}].
On Document · always available · C nexpdf_outlines_json
set_outlines_json
doc.set_outlines_json(json: Optional[str] = None) -> intReplaces the bookmarks with a JSON tree in the same shape.
On Document · module editor · C nexpdf_set_outlines_json
page_labels_json
doc.page_labels_json() -> strPage labels: {"labels":["i","ii","1"],"ranges":[{"start":0,"style":"roman","prefix":"","first":1}]}.
On Document · always available · C nexpdf_page_labels_json
set_page_labels_json
doc.set_page_labels_json(json: Optional[str] = None) -> intSets the page label ranges ([] removes the labels). Styles: decimal, roman, ROMAN, letters, LETTERS, none.
On Document · module editor · C nexpdf_set_page_labels_json
layers_json
doc.layers_json() -> strThe optional content groups (layers): [{"num","gen","name","visible","printable"}].
On Document · always available · C nexpdf_layers_json
set_layer_visible
doc.set_layer_visible(num: int, generation: int, visible: int) -> intShows or hides a layer.
On Document · always available · C nexpdf_set_layer_visible
attachments_json
doc.attachments_json() -> strThe embedded files: [{"name","description","mime","size","page"}]; page is null for document-level files.
On Document · always available · C nexpdf_attachments_json
attachment_data
doc.attachment_data(name: Optional[str] = None) -> bytesThe bytes of an embedded file.
On Document · always available · C nexpdf_attachment_data
add_attachment
doc.add_attachment(name: Optional[str], data: bytes, mime: Optional[str] = None, description: Optional[str] = None) -> intEmbeds a file at document level.
On Document · module editor · C nexpdf_add_attachment
remove_attachment
doc.remove_attachment(name: Optional[str] = None) -> intRemoves an embedded file.
On Document · module editor · C nexpdf_remove_attachment
Encryption, watermarks and stamping
encrypt_aes256
doc.encrypt_aes256(user_pw: Optional[str] = None, owner_pw: Optional[str] = None) -> intEncrypts with AES-256 using a user (open) password and an owner password.
On Document · module security · C nexpdf_encrypt_aes256
encrypt_with_permissions
doc.encrypt_with_permissions(user_pw: Optional[str], owner_pw: Optional[str], permissions: int) -> intEncrypts with AES-256 and a permission mask: print 1, modify 2, copy 4, annotate 8, fill forms 16, assemble 32.
On Document · module security · C nexpdf_encrypt_with_permissions
security_json
doc.security_json() -> strThe encryption state: {"encrypted","revision","owner","print","modify","copy","annotate","fill_forms","assemble"}.
On Document · always available · C nexpdf_security_json
remove_password
doc.remove_password(password: Optional[str] = None) -> intRemoves the protection. Needs owner access: the document was opened with the owner password, or pass it here.
On Document · module security · C nexpdf_remove_password
add_watermark
doc.add_watermark(text: Optional[str] = None) -> intStamps a text watermark on every page.
On Document · module security · C nexpdf_add_watermark
remove_watermarks
doc.remove_watermarks() -> intRemoves the watermarks NexPDF added.
On Document · module security · C nexpdf_remove_watermarks
add_header_footer
doc.add_header_footer(header: Optional[str], footer: Optional[str], font_size: float) -> intAdds a header and/or footer to every page. {page} and {total} are replaced; a font size of 0 or less uses the default.
On Document · module security · C nexpdf_add_header_footer
add_bates
doc.add_bates(prefix: Optional[str], start: int, digits: int) -> intAdds Bates numbering: prefix, first number and number of digits.
On Document · module security · C nexpdf_add_bates
Redaction
apply_redaction
doc.apply_redaction(page_index: int, llx: float, lly: float, urx: float, ury: float, fill_white: int) -> intPermanently removes the text, images and annotations under a rectangle and paints an opaque box over it, black or white.
On Document · module redaction · C nexpdf_apply_redaction
redact_matches
doc.redact_matches(query: Optional[str], mode: int, fill_white: int) -> intFinds 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 Document · module redaction · C nexpdf_redact_matches
Digital signatures
sign_pades
doc.sign_pades(signer: Optional[str] = None, reason: Optional[str] = None, location: Optional[str] = None) -> bytesSigns 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 Document · module signatures · C nexpdf_sign_pades
sign_pkcs12
doc.sign_pkcs12(p12: bytes, password: Optional[str] = None, options_json: Optional[str] = None) -> bytesSigns 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 Document · module signatures · C nexpdf_sign_pkcs12
pkcs12_info_json
nexpdf.pkcs12_info_json(data: bytes, password: Optional[str] = None) -> strThe certificate summary of a PKCS#12 file; fails with "incorrect password" on a wrong password.
On nexpdf · module signatures · C nexpdf_pkcs12_info_json
prepare_external_signature
doc.prepare_external_signature(cert: bytes, options_json: Optional[str] = None) -> bytesExternal 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 Document · module signatures · C nexpdf_prepare_external_signature
external_signature_data
nexpdf.external_signature_data(prepared: bytes, cert: bytes) -> bytesExternal signing, step 2: the bytes to sign (DER signed attributes; sign their SHA-256 on devices that take a digest).
On nexpdf · module signatures · C nexpdf_external_signature_data
complete_external_signature
nexpdf.complete_external_signature(prepared: bytes, cert: bytes, signature: bytes, algorithm: int, options_json: Optional[str] = None) -> bytesExternal signing, step 3: embeds the signature and returns the signed PDF. algorithm: 0 RSA PKCS#1 v1.5 SHA-256, 1 ECDSA SHA-256. Options: {"tsa_url":"...","ltv":true}.
On nexpdf · module signatures · C nexpdf_complete_external_signature
verify_signatures_json
nexpdf.verify_signatures_json(data: bytes) -> strVerifies every signature of a signed file (its exact bytes). Each entry has field, signer, subject, digest_ok, signature_ok, covers_whole_document, reason, signing_time, timestamp_ok, chain_ok, trusted, revocation, ltv, level and more.
On nexpdf · always available · C nexpdf_verify_signatures_json
verify_signatures_with_roots_json
nexpdf.verify_signatures_with_roots_json(data: bytes, roots_pem: Optional[str] = None) -> strVerifies the signatures treating the PEM certificates in roots_pem as trust anchors.
On nexpdf · module signatures · C nexpdf_verify_signatures_with_roots_json
add_ltv
nexpdf.add_ltv(data: bytes) -> bytesAdds long-term validation data (DSS with OCSP responses and CRLs) to a signed file.
On nexpdf · module signatures · C nexpdf_add_ltv
add_document_timestamp
doc.add_document_timestamp(options_json: Optional[str] = None) -> bytesAdds 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 Document · module signatures · C nexpdf_add_document_timestamp
add_document_timestamp_bytes
nexpdf.add_document_timestamp_bytes(data: bytes, options_json: Optional[str] = None) -> bytesAdds a document timestamp to the bytes of a PDF file (for example straight from signing). Same options. Returns the new file.
On nexpdf · module signatures · C nexpdf_add_document_timestamp_bytes
prepare_document_timestamp
doc.prepare_document_timestamp(options_json: Optional[str] = None) -> bytesDocument timestamp from your own TSA or HSM, step 1: the PDF with an empty timestamp (options as for adding one, without tsa_url).
On Document · module signatures · C nexpdf_prepare_document_timestamp
document_timestamp_request
nexpdf.document_timestamp_request(prepared: bytes, hash: Optional[str] = None) -> bytesDocument timestamp, step 2: the DER TimeStampReq to send to the TSA as application/timestamp-query (hash SHA-256 by default).
On nexpdf · module signatures · C nexpdf_document_timestamp_request
complete_document_timestamp
nexpdf.complete_document_timestamp(prepared: bytes, token: bytes) -> bytesDocument timestamp, step 3: the timestamped PDF, from the prepared file and the TSA token (TimeStampResp or TimeStampToken).
On nexpdf · module signatures · C nexpdf_complete_document_timestamp
signature_timestamp_request
nexpdf.signature_timestamp_request(data: bytes, hash: Optional[str] = None) -> bytesB-T in steps: the DER TimeStampReq over the value of the last signature (SHA-256 by default), to POST to the TSA as application/timestamp-query.
On nexpdf · module signatures · C nexpdf_signature_timestamp_request
add_signature_timestamp
nexpdf.add_signature_timestamp(data: bytes, token: bytes) -> bytesB-T in steps: stores the TSA answer (TimeStampResp or TimeStampToken) in the last signature, signed bytes unchanged, and returns the PDF.
On nexpdf · module signatures · C nexpdf_add_signature_timestamp
ltv_requests_json
nexpdf.ltv_requests_json(data: bytes, responses_json: Optional[str] = None) -> strB-LT in steps: the HTTP requests (OCSP, CRL, certificates) the validation data still needs, given the answers so far; [] when nothing is missing.
On nexpdf · module signatures · C nexpdf_ltv_requests_json
add_ltv_with_responses
nexpdf.add_ltv_with_responses(data: bytes, responses_json: Optional[str] = None) -> bytesB-LT in steps: adds the /DSS from the fetched answers (missing ones count as failed) as an incremental update and returns the PDF.
On nexpdf · module signatures · C nexpdf_add_ltv_with_responses
validate_lta_json
nexpdf.validate_lta_json(data: bytes, trust_roots_pem: Optional[str] = None) -> strFull PAdES B-LTA validation: whether the /DSS of each time-stamped revision holds every certificate and verified OCSP or CRL entry the earlier signatures and time-stamps need. Returns complete and timestamps with their issues.
On nexpdf · module signatures · C nexpdf_validate_lta_json
PDF/A, PDF/X and PDF/UA
convert_pdfa
doc.convert_pdfa() -> intConverts the document to PDF/A (ISO 19005) for archiving.
On Document · module standards · C nexpdf_convert_pdfa
convert_pdfx
doc.convert_pdfx() -> intConverts the document to PDF/X for print exchange.
On Document · module standards · C nexpdf_convert_pdfx
auto_tag
doc.auto_tag(lang: Optional[str], force: int) -> strTags 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 Document · module standards · C nexpdf_auto_tag
validate_pdfa_json
doc.validate_pdfa_json(level: Optional[str] = None) -> strRule-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 Document · module standards · C nexpdf_validate_pdfa_json
validate_pdfua_json
doc.validate_pdfua_json() -> strPDF/UA validation (PDF/UA-1, or PDF/UA-2 when declared), with the same report as PDF/A validation.
On Document · module standards · C nexpdf_validate_pdfua_json
convert_pdfa_level
doc.convert_pdfa_level(level: Optional[str] = None) -> intConverts 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 Document · module standards · C nexpdf_convert_pdfa_level
convert_pdfa_json
doc.convert_pdfa_json(level: Optional[str], flatten_dpi: float, substitute_fonts: int) -> strConverts 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 Document · module standards · C nexpdf_convert_pdfa_json
convert_pdfua_json
doc.convert_pdfua_json(part: int, lang: Optional[str] = None) -> strConverts 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 Document · module standards · C nexpdf_convert_pdfua_json
validate_pdfua_part_json
doc.validate_pdfua_part_json(part: int) -> strValidates 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 Document · module standards · C nexpdf_validate_pdfua_part_json
register_substitute_font
nexpdf.register_substitute_font(data: bytes) -> strRegisters TrueType font data for PDF/A and PDF/UA font substitution: non-embedded fonts with the same PostScript or family name use it. Returns the PostScript name, or nothing when the data is not a TrueType font with glyf outlines.
On nexpdf · module standards · C nexpdf_register_substitute_font
OCR
ocr
doc.ocr(options_json: Optional[str] = None) -> strRecognises 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 Document · module ocr · C nexpdf_ocr
ocr_load_model
nexpdf.ocr_load_model(options_json: Optional[str], model: bytes, dictionary: Optional[str] = None) -> intLoads a neural OCR model (ONNX) at run time: {"kind":"detection"|"recognition"|"classification","languages","name","input_height","max_side"}; a recognition model needs its character dictionary, a detection model or a text-direction classifier (0°/180°) takes none.
On nexpdf · module ocr · C nexpdf_ocr_load_model
ocr_models_json
nexpdf.ocr_models_json() -> strThe loaded OCR models: kind, name, languages, symbols, size.
On nexpdf · module ocr · C nexpdf_ocr_models_json
ocr_unload_models
nexpdf.ocr_unload_models(languages: Optional[str] = None) -> intUnloads the OCR models of the given languages (all when empty). Returns the number removed.
On nexpdf · module ocr · C nexpdf_ocr_unload_models
Compare, optimise and memory
compare_json
doc.compare_json(b: "Document", dpi: float) -> strCompares two documents (text and visual differences per page) at the given resolution, as JSON.
On Document · always available · C nexpdf_compare_json
compare_overlay_png
doc.compare_overlay_png(b: "Document", page_index: int, dpi: float) -> bytesA PNG overlay of the visual differences of one page of two documents.
On Document · always available · C nexpdf_compare_overlay_png
optimize
doc.optimize() -> strOptimises the document (removes unused objects, recompresses streams); returns a JSON report.
On Document · module editor · C nexpdf_optimize
subset_fonts
doc.subset_fonts() -> strSubsets the embedded fonts to the glyphs the document uses; returns a JSON report.
On Document · module editor · C nexpdf_subset_fonts
trim_memory
doc.trim_memory() -> intDrops cached data of the document; returns the bytes freed.
On Document · always available · C nexpdf_trim_memory
memory_usage_bytes
doc.memory_usage_bytes() -> intApproximate memory used by the document, in bytes.
On Document · always available · C nexpdf_memory_usage_bytes
compare_text_json
doc.compare_text_json(b: "Document", options_json: Optional[str] = None) -> strWord-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 Document · always available · C nexpdf_compare_text_json
compare_annotate
doc.compare_annotate(b: "Document", options_json: Optional[str] = None) -> bytesThe word-level comparison as a new PDF with highlight annotations (deleted red, inserted green, moved blue). Options add output, author and the colours.
On Document · always available · C nexpdf_compare_annotate
Other
set_annotation_flags
doc.set_annotation_flags(num: int, generation: int, flags_json: Optional[str] = None) -> intAnnotation 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 Document
set_annotation_style
doc.set_annotation_style(num: int, generation: int, style_json: Optional[str] = None) -> intColour, 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 Document