Module Pdf
module Pdf: sig
.. end
Representing PDF Files in Memory
type
stream =
A stream is either in memory, or at a position and of a length in an
Io.input
type
pdfobject =
| |
Null |
| |
Boolean of bool |
| |
Integer of int |
| |
Real of float |
| |
String of string |
| |
Name of string |
| |
Array of pdfobject list |
| |
Dictionary of (string * pdfobject) list |
| |
Stream of (pdfobject * stream) Pervasives.ref |
| |
Indirect of int |
PDF objects.
type
pdfobjects
The type of a map from PDF object numbers to PDF objects
type
pdfdoc = {
|
mutable major : int ; |
|
mutable minor : int ; |
|
mutable root : int ; |
|
mutable objects : pdfobjects ; |
|
mutable trailerdict : pdfobject ; |
}
A Pdf document. Major and minor version numbers, pointer to root, file
objects and the trailer dictionary as a Dictionary pdfobject
.
val empty : unit -> pdfdoc
The empty document (PDF 1.0, no objects, no root, empty trailer dictionary).
Note this is not a well-formed PDF.
exception PDFError of string
Any function may return this.
val getstream : pdfobject -> unit
Get a stream from disc if it hasn't already been got. The input is a
Stream pdfobject
.
val getnum : pdfobject -> float
Return a float from either a Real
or an Int
val parse_rectangle : pdfobject -> float * float * float * float
Parse a PDF rectangle structure into min x, min y, max x, max y.
val parse_matrix : pdfdoc -> string -> pdfobject -> Transform.transform_matrix
Calling 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 : Transform.transform_matrix -> pdfobject
Build a matrix pdfobject
.
val lookup_obj : pdfdoc -> int -> pdfobject
Lookup an object in a document, parsing it if required. Raises Not_found
if the object does not exist.
val lookup_fail : string -> pdfdoc -> string -> pdfobject -> pdfobject
lookup_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 -> pdfdoc -> string -> pdfobject -> pdfobject
Same, but with customised exception.
val lookup_direct : pdfdoc -> string -> pdfobject -> pdfobject option
lookup_direct doc key dict
looks up the key returning an option type.
val lookup_direct_orelse : pdfdoc -> string -> string -> pdfobject -> pdfobject option
Same, but allow alternative key.
val remove_dict_entry : pdfobject -> string -> pdfobject
Remove a dictionary entry, if it exists.
val replace_dict_entry : pdfobject -> string -> pdfobject -> pdfobject
Replace a dictionary entry, raising Not_found
if it's not there.
val add_dict_entry : pdfobject -> string -> pdfobject -> pdfobject
Add a dictionary entry, replacing if already there.
val direct : pdfdoc -> pdfobject -> pdfobject
Make a PDF object direct -- that is, follow any indirect links.
val objiter : (int -> pdfobject -> unit) -> pdfdoc -> unit
Iterate over the objects in a document. The iterating functions recieves both
object number and object from the object map.
val objiter_gen : (int -> int -> pdfobject -> unit) -> pdfdoc -> unit
Iterate over the objects in a document. The iterating functions recieves
object number, generation number and object from the object map.
val objmap : (pdfobject -> pdfobject) -> pdfdoc -> unit
Map over all pdf objects in a document. Does not include trailer dictionary.
val objcard : pdfdoc -> int
Return the cardinality of the object map.
val addobj : pdfdoc -> pdfobject -> int
Add an object. Returns the number chosen.
val addobj_given_num : pdfdoc -> int * pdfobject -> unit
Same, but pick a number ourselves.
val map_stream : (pdfobject -> pdfobject) -> pdfdoc -> pdfdoc
Map over just the stream objects in a document.
val iter_stream : (pdfobject -> unit) -> pdfdoc -> unit
Iterate over just the stream objects in a document.
val renumber_pdfs : pdfdoc list -> pdfdoc list
Make a number of PDF documents contain no mutual object numbers. They can
then be merged etc. without clashes.
val remove_unreferenced : pdfdoc -> unit
Garbage-collect a pdf document.
val unique_key : string -> pdfobject -> string
Given 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).