MuPDF X.Y.Z

pdf/xref.h

Index

typedef

struct

function

Xref

function pdf_create_object

int
pdf_create_object (
        fz_context *ctx,
        pdf_document *doc
)

Allocate a slot in the xref table and return a fresh unused object number.

function pdf_delete_object

void
pdf_delete_object (
        fz_context *ctx,
        pdf_document *doc,
        int num
)

Remove object from xref table, marking the slot as free.

function pdf_update_object

void
pdf_update_object (
        fz_context *ctx,
        pdf_document *doc,
        int num,
        pdf_obj *obj
)

Replace object in xref table with the passed in object.

function pdf_update_stream

void
pdf_update_stream (
        fz_context *ctx,
        pdf_document *doc,
        pdf_obj *ref,
        fz_buffer *buf,
        int compressed
)

Replace stream contents for object in xref table with the passed in buffer.

The buffer contents must match the /Filter setting if ‘compressed’ is true. If ‘compressed’ is false, the /Filter and /DecodeParms entries are deleted. The /Length entry is updated.

function pdf_is_local_object

int
pdf_is_local_object (
        fz_context *ctx,
        pdf_document *doc,
        pdf_obj *obj
)

Return true if ‘obj’ is an indirect reference to an object that is held by the “local” xref section.

function pdf_add_object

pdf_obj *
pdf_add_object (
        fz_context *ctx,
        pdf_document *doc,
        pdf_obj *obj
)

function pdf_add_object_drop

pdf_obj *
pdf_add_object_drop (
        fz_context *ctx,
        pdf_document *doc,
        pdf_obj *obj
)

function pdf_add_stream

pdf_obj *
pdf_add_stream (
        fz_context *ctx,
        pdf_document *doc,
        fz_buffer *buf,
        pdf_obj *obj,
        int compressed
)

function pdf_add_new_dict

pdf_obj *
pdf_add_new_dict (
        fz_context *ctx,
        pdf_document *doc,
        int initial
)

function pdf_add_new_array

pdf_obj *
pdf_add_new_array (
        fz_context *ctx,
        pdf_document *doc,
        int initial
)

struct pdf_xref_entry

struct pdf_xref_entry
{
        char type;              /* 0=unset (f)ree i(n)use (o)bjstm */
        unsigned char marked;   /* marked to keep alive with pdf_mark_xref */
        unsigned short gen;     /* generation / objstm index */
        int num;                /* original object number (for decryption after renumbering) */
        int64_t ofs;            /* file offset / objstm object number */
        int64_t stm_ofs;        /* on-disk stream */
        fz_buffer *stm_buf;     /* in-memory stream (for updated objects) */
        pdf_obj *obj;           /* stored/cached object */
}

struct pdf_xref_subsec

struct pdf_xref_subsec
{
        struct pdf_xref_subsec *next;
        int len;
        int start;
        pdf_xref_entry *table;
}

struct pdf_xref

struct pdf_xref
{
        int num_objects;
        int num_subsecs;
        pdf_xref_subsec *subsec;
        pdf_obj *trailer;
        pdf_obj *pre_repair_trailer;
        pdf_unsaved_sig *unsaved_sigs;
        pdf_unsaved_sig **unsaved_sigs_end;
        int64_t end_ofs; /* file offset to end of xref */
}

function pdf_cache_object

pdf_xref_entry *
pdf_cache_object (
        fz_context *ctx,
        pdf_document *doc,
        int num
)

Retrieve the pdf_xref_entry for a given object.

This can cause xref reorganisations (solidifications etc) due to repairs, so all held pdf_xref_entries should be considered invalid after this call (other than the returned one).

function pdf_object_exists

int
pdf_object_exists (
        fz_context *ctx,
        pdf_document *doc,
        int num
)

function pdf_count_objects

int
pdf_count_objects (
        fz_context *ctx,
        pdf_document *doc
)

function pdf_resolve_indirect

pdf_obj *
pdf_resolve_indirect (
        fz_context *ctx,
        pdf_obj *ref
)

Resolve an indirect object (or chain of objects).

This can cause xref reorganisations (solidifications etc) due to repairs, so all held pdf_xref_entries should be considered invalid after this call (other than the returned one).

function pdf_resolve_indirect_chain

pdf_obj *
pdf_resolve_indirect_chain (
        fz_context *ctx,
        pdf_obj *ref
)

function pdf_load_object

pdf_obj *
pdf_load_object (
        fz_context *ctx,
        pdf_document *doc,
        int num
)

Load a given object.

This can cause xref reorganisations (solidifications etc) due to repairs, so all held pdf_xref_entries should be considered invalid after this call (other than the returned one).

function pdf_load_unencrypted_object

pdf_obj *
pdf_load_unencrypted_object (
        fz_context *ctx,
        pdf_document *doc,
        int num
)

function pdf_load_raw_stream_number

fz_buffer *
pdf_load_raw_stream_number (
        fz_context *ctx,
        pdf_document *doc,
        int num
)

Load raw (compressed but decrypted) contents of a stream into buf.

function pdf_load_raw_stream

fz_buffer *
pdf_load_raw_stream (
        fz_context *ctx,
        pdf_obj *ref
)

function pdf_internalize_external_stream

void
pdf_internalize_external_stream (
        fz_context *ctx,
        pdf_document *doc,
        int num
)

Move an external stream to be an internal one.

function pdf_load_stream_number

fz_buffer *
pdf_load_stream_number (
        fz_context *ctx,
        pdf_document *doc,
        int num
)

Load uncompressed contents of a stream into buf.

function pdf_load_stream

fz_buffer *
pdf_load_stream (
        fz_context *ctx,
        pdf_obj *ref
)

function pdf_open_raw_stream_number

fz_stream *
pdf_open_raw_stream_number (
        fz_context *ctx,
        pdf_document *doc,
        int num
)

Open a stream for reading the raw (compressed but decrypted) data.

function pdf_open_raw_stream

fz_stream *
pdf_open_raw_stream (
        fz_context *ctx,
        pdf_obj *ref
)

function pdf_open_stream_number

fz_stream *
pdf_open_stream_number (
        fz_context *ctx,
        pdf_document *doc,
        int num
)

Open a stream for reading uncompressed data. Put the opened file in doc->stream. Using doc->file while a stream is open is a Bad idea.

function pdf_open_stream

fz_stream *
pdf_open_stream (
        fz_context *ctx,
        pdf_obj *ref
)

function pdf_open_inline_stream

fz_stream *
pdf_open_inline_stream (
        fz_context *ctx,
        pdf_document *doc,
        pdf_obj *stmobj,
        size_t length,
        fz_stream *chain,
        fz_compression_params *params
)

Construct a filter to decode a stream, without constraining to stream length, and without decryption.

function pdf_load_compressed_stream

fz_compressed_buffer *
pdf_load_compressed_stream (
        fz_context *ctx,
        pdf_document *doc,
        int num,
        size_t worst_case
)

function pdf_load_compressed_inline_image

void
pdf_load_compressed_inline_image (
        fz_context *ctx,
        pdf_document *doc,
        pdf_obj *dict,
        size_t length,
        fz_stream *cstm,
        int indexed,
        fz_compressed_image *image
)

function pdf_open_stream_with_offset

fz_stream *
pdf_open_stream_with_offset (
        fz_context *ctx,
        pdf_document *doc,
        int num,
        pdf_obj *dict,
        int64_t stm_ofs
)

function pdf_open_contents_stream

fz_stream *
pdf_open_contents_stream (
        fz_context *ctx,
        pdf_document *doc,
        pdf_obj *obj
)

function pdf_load_image_stream

fz_buffer *
pdf_load_image_stream (
        fz_context *ctx,
        pdf_document *doc,
        int num,
        fz_compression_params *params,
        int *truncated,
        size_t worst_case
)

function pdf_version

int
pdf_version (
        fz_context *ctx,
        pdf_document *doc
)

function pdf_trailer

pdf_obj *
pdf_trailer (
        fz_context *ctx,
        pdf_document *doc
)

function pdf_set_trailer

void
pdf_set_trailer (
        fz_context *ctx,
        pdf_document *doc,
        pdf_obj *obj
)

function pdf_set_populating_xref_trailer

void
pdf_set_populating_xref_trailer (
        fz_context *ctx,
        pdf_document *doc,
        pdf_obj *trailer
)

function pdf_xref_len

int
pdf_xref_len (
        fz_context *ctx,
        pdf_document *doc
)

function pdf_metadata

pdf_obj *
pdf_metadata (
        fz_context *ctx,
        pdf_document *doc
)

function pdf_get_populating_xref_entry

pdf_xref_entry *
pdf_get_populating_xref_entry (
        fz_context *ctx,
        pdf_document *doc,
        int i
)

Used while reading the individual xref sections from a file.

function pdf_get_xref_entry

pdf_xref_entry *
pdf_get_xref_entry (
        fz_context *ctx,
        pdf_document *doc,
        int i
)

Used after loading a document to access entries.

This will never throw anything, or return NULL if it is only asked to return objects in range within a ‘solid’ xref.

This may “solidify” the xref (so can cause allocations).

function pdf_xref_entry_map

void pdf_xref_entry_map(fz_context *ctx, pdf_document *doc, void (*fn)(fz_context *, pdf_xref_entry *, int i, pdf_document *doc, void *), void *arg)

Map a function across all xref entries in a document.

function pdf_get_xref_entry_no_change

pdf_xref_entry *
pdf_get_xref_entry_no_change (
        fz_context *ctx,
        pdf_document *doc,
        int i
)

Used after loading a document to access entries.

This will never throw anything, or return NULL if it is only asked to return objects in range within a ‘solid’ xref.

This will never “solidify” the xref, so no entry may be found (NULL will be returned) for free entries.

Called with a valid i, this will never try/catch or throw.

function pdf_get_xref_entry_no_null

pdf_xref_entry *
pdf_get_xref_entry_no_null (
        fz_context *ctx,
        pdf_document *doc,
        int i
)

function pdf_replace_xref

void
pdf_replace_xref (
        fz_context *ctx,
        pdf_document *doc,
        pdf_xref_entry *entries,
        int n
)

function pdf_forget_xref

void
pdf_forget_xref (
        fz_context *ctx,
        pdf_document *doc
)

function pdf_get_incremental_xref_entry

pdf_xref_entry *
pdf_get_incremental_xref_entry (
        fz_context *ctx,
        pdf_document *doc,
        int i
)

function pdf_xref_ensure_incremental_object

int
pdf_xref_ensure_incremental_object (
        fz_context *ctx,
        pdf_document *doc,
        int num
)

Ensure that an object has been cloned into the incremental xref section.

function pdf_xref_is_incremental

int
pdf_xref_is_incremental (
        fz_context *ctx,
        pdf_document *doc,
        int num
)

function pdf_xref_store_unsaved_signature

void
pdf_xref_store_unsaved_signature (
        fz_context *ctx,
        pdf_document *doc,
        pdf_obj *field,
        pdf_pkcs7_signer *signer
)

function pdf_xref_remove_unsaved_signature

void
pdf_xref_remove_unsaved_signature (
        fz_context *ctx,
        pdf_document *doc,
        pdf_obj *field
)

function pdf_xref_obj_is_unsaved_signature

int
pdf_xref_obj_is_unsaved_signature (
        pdf_document *doc,
        pdf_obj *obj
)

function pdf_xref_ensure_local_object

void
pdf_xref_ensure_local_object (
        fz_context *ctx,
        pdf_document *doc,
        int num
)

function pdf_obj_is_incremental

int
pdf_obj_is_incremental (
        fz_context *ctx,
        pdf_obj *obj
)

function pdf_repair_xref

void
pdf_repair_xref (
        fz_context *ctx,
        pdf_document *doc
)

function pdf_ensure_solid_xref

void
pdf_ensure_solid_xref (
        fz_context *ctx,
        pdf_document *doc,
        int num
)

Ensure that the current populating xref has a single subsection that covers the entire range.

function pdf_mark_xref

void
pdf_mark_xref (
        fz_context *ctx,
        pdf_document *doc
)

function pdf_clear_xref

void
pdf_clear_xref (
        fz_context *ctx,
        pdf_document *doc
)

function pdf_clear_xref_to_mark

void
pdf_clear_xref_to_mark (
        fz_context *ctx,
        pdf_document *doc
)

function pdf_repair_obj

int
pdf_repair_obj (
        fz_context *ctx,
        pdf_document *doc,
        pdf_lexbuf *buf,
        int64_t *stmofsp,
        int64_t *stmlenp,
        pdf_obj **encrypt,
        pdf_obj **id,
        pdf_obj **page,
        int64_t *tmpofs,
        pdf_obj **root
)

function pdf_progressive_advance

pdf_obj *
pdf_progressive_advance (
        fz_context *ctx,
        pdf_document *doc,
        int pagenum
)

function pdf_count_versions

int
pdf_count_versions (
        fz_context *ctx,
        pdf_document *doc
)

Return the number of versions that there are in a file. i.e. 1 + the number of updates that the file on disc has been through. i.e. internal unsaved changes to the file (such as appearance streams) are ignored. Also, the initial write of a linearized file (which appears as a base file write + an incremental update) is treated as a single version.

function pdf_count_unsaved_versions

int
pdf_count_unsaved_versions (
        fz_context *ctx,
        pdf_document *doc
)

function pdf_validate_changes

int
pdf_validate_changes (
        fz_context *ctx,
        pdf_document *doc,
        int version
)

function pdf_doc_was_linearized

int
pdf_doc_was_linearized (
        fz_context *ctx,
        pdf_document *doc
)

typedef pdf_locked_fields

typedef struct pdf_locked_fields pdf_locked_fields

function pdf_is_field_locked

int
pdf_is_field_locked (
        fz_context *ctx,
        pdf_locked_fields *locked,
        const char *name
)

function pdf_drop_locked_fields

void
pdf_drop_locked_fields (
        fz_context *ctx,
        pdf_locked_fields *locked
)

function pdf_find_locked_fields

pdf_locked_fields *
pdf_find_locked_fields (
        fz_context *ctx,
        pdf_document *doc,
        int version
)

function pdf_find_locked_fields_for_sig

pdf_locked_fields *
pdf_find_locked_fields_for_sig (
        fz_context *ctx,
        pdf_document *doc,
        pdf_obj *sig
)

function pdf_validate_change_history

int
pdf_validate_change_history (
        fz_context *ctx,
        pdf_document *doc
)

Check the entire history of the document, and return the number of the last version that checked out OK. i.e. 0 = “the entire history checks out OK”. n = “none of the history checked out OK”.

function pdf_find_version_for_obj

int
pdf_find_version_for_obj (
        fz_context *ctx,
        pdf_document *doc,
        pdf_obj *obj
)

Find which version of a document the current version of obj was defined in.

version = 0 = latest, 1 = previous update etc, allowing for the first incremental update in a linearized file being ignored.

function pdf_validate_signature

int
pdf_validate_signature (
        fz_context *ctx,
        pdf_document *doc,
        pdf_obj *field
)

Return the number of updates ago when a signature field became invalid, not counting any unsaved changes.

Thus: -1 => Has changed in the current unsaved changes. 0 => still valid. 1 => became invalid on the last save n => became invalid n saves ago

function pdf_validate_signature_widget

int
pdf_validate_signature_widget (
        fz_context *ctx,
        pdf_annot *widget
)

function pdf_was_pure_xfa

int
pdf_was_pure_xfa (
        fz_context *ctx,
        pdf_document *doc
)

function pdf_new_local_xref

pdf_xref *
pdf_new_local_xref (
        fz_context *ctx,
        pdf_document *doc
)

Local xrefs - designed for holding stuff that shouldn’t be written back into the actual document, such as synthesized appearance streams.

function pdf_drop_local_xref

void
pdf_drop_local_xref (
        fz_context *ctx,
        pdf_xref *xref
)

function pdf_drop_local_xref_and_resources

void
pdf_drop_local_xref_and_resources (
        fz_context *ctx,
        pdf_document *doc
)

function pdf_debug_doc_changes

void
pdf_debug_doc_changes (
        fz_context *ctx,
        pdf_document *doc
)

Debug call to dump the incremental/local xrefs to the debug channel.