module Pdf:sig..end
Representing PDF Files in Memory
type toget 
type stream = 
| | 
Got of  | 
| | 
ToGet of  | 
A stream is either in memory, or at a position and of a length in an
Pdfio.input.
type pdfobject = 
| | 
Null | 
| | 
Boolean of  | 
| | 
Integer of  | 
| | 
Real of  | 
| | 
String of  | 
| | 
Name of  | 
| | 
Array of  | 
| | 
Dictionary of  | 
| | 
Stream of  | 
| | 
Indirect of  | 
PDF objects. An object is a tree-like structure containing various things. A PDF file is basically a directed graph of objects.
You should not expect to manipulate these types and functions directly.
type objectdata = 
| | 
Parsed of  | 
| | 
ParsedAlreadyDecrypted of  | 
| | 
ToParse | 
| | 
ToParseFromObjectStream of  | 
This type represents a possibly-parsed, possibly-decrypted, possibly-read-from-an-object-stream object.
typepdfobjmap_key =int
typepdfobjmap =(pdfobjmap_key, objectdata Stdlib.ref * int) Stdlib.Hashtbl.t
The object map maps object numbers pdfobjmap_key to a reference to the
object data and the generation number
val pdfobjmap_empty : unit -> pdfobjmapMake an empty object map
val pdfobjmap_find : pdfobjmap_key -> pdfobjmap -> objectdata Stdlib.ref * intFind an object in the object map
type pdfobjects = {
   | 
mutable maxobjnum :  | 
   | 
mutable parse :  | 
   | 
mutable pdfobjects :  | 
   | 
mutable object_stream_ids :  | 
}
The objects. Again, you won't normally manipulate this directly.
maxobjnum is the biggest object number seen yet. parse is a function to
parse a non-object stream object given its object number, pdfobjects is the
object map itself. object_stream_ids is a hash table of (object number,
was-stored-in-obect-stream-number) pairs, which is used to reconstruct stream
objects when preserving them upon write.
type saved_encryption = {
   | 
from_get_encryption_values :  | 
   | 
encrypt_metadata :  | 
   | 
perms :  | 
}
type deferred_encryption = {
   | 
crypt_type :  | 
   | 
file_encryption_key :  | 
   | 
obj :  | 
   | 
gen :  | 
   | 
key :  | 
   | 
keylength :  | 
   | 
r :  | 
}
type t = {
   | 
mutable major :  | 
   | 
mutable minor :  | 
   | 
mutable root :  | 
   | 
mutable objects :  | 
   | 
mutable trailerdict :  | 
   | 
mutable was_linearized :  | 
   | 
mutable saved_encryption :  | 
}
A Pdf document. Major and minor version numbers, object number of root, the
objects objects and the trailer dictionary as a Dictionary pdfobject.
val empty : unit -> tThe empty document (PDF 1.0, no objects, no root, empty trailer dictionary). Note this is not a well-formed PDF.
exception PDFError of string
This exception is raised when some malformity in a PDF is found -- quite a wide range of circumstances, and may be raised from many functions.
val input_pdferror : Pdfio.input -> string -> stringThis function, given a Pdfio.input and an ancilliary string, builds an
error string which includes the source of the Pdfio.input (filename, string,
bytes etc) so we can trace what it was originally built from
val getstream : pdfobject -> unitGet a stream from disc if it hasn't already been got. The input is a
Stream pdfobject.
val getnum : t -> pdfobject -> floatReturn a float from a Real, an Int or an Indirect
val lookup_obj : t -> int -> pdfobjectLookup an object in a document, parsing it if required. Raises Not_found
if the object does not exist.
val lookup_fail : string -> t -> string -> pdfobject -> pdfobjectlookup_fail errtext doc key dict looks up a key in a PDF dictionary or the
dictionary of a PDF stream. Fails with PDFError errtext if the key is not
found. Follows indirect object links.
val lookup_exception : exn -> t -> string -> pdfobject -> pdfobjectSame, but with customised exception.
val lookup_direct : t -> string -> pdfobject -> pdfobject optionlookup_direct doc key dict looks up the key, resolving indirections at
    source and destination, returning an option type.
val lookup_immediate : string -> pdfobject -> pdfobject optionlookup_immediate key dict looks up the key returning the value, without
following indirects at either source or destination.
val lookup_chain : t -> pdfobject -> string list -> pdfobject optionlookup_chain doc start keys looks up the key in a nested dictionary. For
    example lookup_chain pdf pdf.Pdf.trailerdict ["/Root"; "/StructTreeRoot";
    "/RoleMap"]
val replace_chain : t -> string list -> pdfobject -> unitreplace_chain doc chain obj sets the object at the given chain from the
    trailer dictionary to the given object. If the final part of the chain does
    not exist, it is created as direct, nested, dictionaries.
val indirect_number : t -> string -> pdfobject -> int optionReturn the object number of an indirect dictionary object, if it is indirect.
val lookup_direct_orelse : t -> string -> string -> pdfobject -> pdfobject optionSame as lookup_direct, but allow a second, alternative key.
val remove_dict_entry : pdfobject -> string -> pdfobjectRemove a dictionary entry, if it exists.
val replace_dict_entry : pdfobject -> string -> pdfobject -> pdfobjectreplace_dict_entry dict key value replaces a dictionary entry, raising Not_found if it's not there.
val add_dict_entry : pdfobject -> string -> pdfobject -> pdfobjectadd_dict_entry dict key value adds a dictionary entry, replacing if already there.
val direct : t -> pdfobject -> pdfobjectMake a PDF object direct -- that is, follow any indirect links.
val objcard : t -> intReturn the size of the object map.
val removeobj : t -> int -> unitRemove the given object
val addobj : t -> pdfobject -> intAdd an object. Returns the number chosen.
val addobj_given_num : t -> int * pdfobject -> unitSame as addobj, but pick a number ourselves.
val parse_rectangle : t -> pdfobject -> float * float * float * floatParse a PDF rectangle structure into min x, min y, max x, max y.
val parse_matrix : t -> string -> pdfobject -> Pdftransform.transform_matrixCalling parse_matrix pdf name dict parses a PDF matrix found under
key name in dictionary dict into a Transform.transform_matrix. If there is
no matrix, the identity matrix is returned.
val make_matrix : Pdftransform.transform_matrix -> pdfobjectBuild a matrix pdfobject.
val renumber_pdfs : t list -> t listMake a number of PDF documents contain no mutual object numbers. They can then be merged etc. without clashes.
val unique_key : string -> pdfobject -> stringGiven a dictionary and a prefix (e.g gs), return a name, starting with the prefix, which is not already in the dictionary (e.g /gs0).
val objiter : (int -> pdfobject -> unit) -> t -> unitIterate over the objects in a document. The iterating functions recieves both object number and object from the object map.
val objiter_inorder : (int -> pdfobject -> unit) -> t -> unitThe same, but in object number order.
val objiter_gen : (int -> int -> pdfobject -> unit) -> t -> unitIterate over the objects in a document. The iterating functions recieves object number, generation number and object from the object map.
val objselfmap : (pdfobject -> pdfobject) -> t -> unitMap over all pdf objects in a document. Does not include trailer dictionary.
val iter_stream : (pdfobject -> unit) -> t -> unitIterate over just the stream objects in a document.
val objselect : (pdfobject -> bool) -> t -> int listSelect objects matching a predicate, and return their object numbers.
val remove_unreferenced : t -> unitGarbage-collect a pdf document.
These functions were previsouly undocumented. They are documented here for now, and in the future will be categorised more sensibly.
val is_whitespace : char -> boolTrue if a character is PDF whitespace.
val is_not_whitespace : char -> boolTrue if a character is not PDF whitespace.
val is_delimiter : char -> boolTrue if a character is a PDF delimiter.
val page_reference_numbers : t -> int listList, in order, the page reference numbers of a PDF's page tree.
val objnumbers : t -> int listList the object numbers in a PDF.
val recurse_dict : (pdfobject -> pdfobject) ->
       (string * pdfobject) list -> pdfobjectUse the given function on each element of a PDF dictionary.
val recurse_array : (pdfobject -> pdfobject) -> pdfobject list -> pdfobjectSimilarly for an Array. The function is applied to each element.
val changes : t -> (int, int) Stdlib.Hashtbl.tCalculate the changes required to renumber a PDF's objects 1..n.
val renumber : (int, int) Stdlib.Hashtbl.t -> t -> tPerform the given renumberings on a PDF.
val renumber_object_parsed : t -> (int, int) Stdlib.Hashtbl.t -> pdfobject -> pdfobjectRenumber an object given a change table.
val bigarray_of_stream : pdfobject -> Pdfio.bytesFetch a stream, if necessary, and return its contents (with no processing).
val objects_of_list : (int -> pdfobject) option ->
       (int * (objectdata Stdlib.ref * int)) list -> pdfobjectsMake a objects entry from a parser and a list of (number, object) pairs.
val objects_referenced : string list ->
       (string * pdfobject) list -> t -> pdfobject -> int listCalling objects_referenced no_follow_entries no_follow_contains pdf
    pdfobject find the objects reachable from the given object. Dictionary
    keys in no_follow_entries are not explored. Dictionaries containing
    entries in no_follow_contains are not explored.
val generate_id : t -> string -> (unit -> float) -> pdfobjectGenerate and ID for a PDF document given its prospective file name (and using the current date and time). If the file name is blank, the ID is still likely to be unique, being based on date and time only. If environment variable CAMLPDF_REPRODUCIBLE_IDS=true is set, the ID will instead be set to a standard value.
val catalog_of_pdf : t -> pdfobjectReturn the document catalog.
val find_indirect : string -> pdfobject -> int optionFind the indirect reference given by the value associated with a key in a dictionary.
val nametree_lookup : t -> pdfobject -> pdfobject -> pdfobject optionCalling nametree_lookup pdf k dict looks up the name in the document's
    name tree
val contents_of_nametree : t -> pdfobject -> (pdfobject * pdfobject) listReturn an ordered list of the key-value pairs in a given name tree.
val deep_copy : t -> tCopy a PDF data structure so that nothing is shared with the original.
val change_id : t -> string -> unitChange the /ID string in a PDF's trailer dicfionary