ExportDocumentJSON
Document exchange
Description
Serializes the complete document object graph to a JSON file. A write failure leaves an existing destination intact
Syntax
Delphi
Function ExportDocumentJSON(Const FileName: WideString; Options: Integer): Integer;Parameters
| FileName | Destination path for the JSON file; must not be empty |
|---|---|
| Options | Bit mask: 1 omits base64 stream payloads and keeps dictionaries only, 2 appends the trailer dictionary; zero writes stream payloads and no trailer entry |
Return values
| 0 | No document is loaded or the file could not be written |
|---|---|
| 1 | The JSON file was written |
Remarks
Options is a bit mask: 1 omits base64 stream payloads and keeps dictionaries only, 2 appends the trailer dictionary. The output is one JSON object whose single key, qpdf, holds an array of two elements: the first reports pdfversion, the second maps each indirect object to an entry keyed obj:N G R, plus a trailer entry when requested. An object that is not a stream appears under value; a stream appears under stream as an object with a dict member and, unless omitted, a base64 data string
Names, strings and indirect references are all written as plain JSON strings: a name without its leading slash, a string as its bytes, a reference as N G R. The JSON alone therefore does not say which of the three a given string was. The layout is specific to this library and is meant for inspection and comparison; despite the name of the top-level key, the file is not interchangeable with JSON written or read by other tools, and it cannot be loaded back into a document
The file contains valid UTF-8 JSON. PDF strings and names preserve raw byte values using JSON Unicode escapes for control and high-bit bytes. Numbers retain their decimal precision, and pdfversion reports the loaded PDF version
Example
PDF.ExportDocumentJSON("dump.json", 2);