![]() |
![]()
| ![]() |
![]()
NAMEPDF::Builder::Basic::PDF::File - Holds the trailers and cross-reference tables for a PDF file SYNOPSIS$p = PDF::Builder::Basic::PDF::File->open("filename.pdf", 1); $p->new_obj($obj_ref); $p->free_obj($obj_ref); $p->append_file(); $p->close_file(); $p->release(); # IMPORTANT! DESCRIPTIONThis class keeps track of the directory aspects of a PDF file. There are two parts to the directory: the main directory object, which is the parent to all other objects, and a chain of cross-reference tables and corresponding trailer dictionaries, starting with the main directory object. INSTANCE VARIABLESWithin this class hierarchy, rather than making everything visible via methods, which would be a lot of work, there are various instance variables which are accessible via associative array referencing. To distinguish instance variables from content variables (which may come from the PDF content itself), each such variable name will start with a space. Variable names which do not start with a space directly reflect elements in a PDF dictionary. In the case of a "PDF::Builder::Basic::PDF::File", the elements reflect those in the trailer dictionary. Since some variables are not designed for class users to access, variables are marked in the documentation with (R) to indicate that such an entry should only be used as read-only information. (P) indicates that the information is private, and not designed for user use at all, but is included in the documentation for completeness and to ensure that nobody else tries to use it.
Each trailer dictionary contains a number of private instance variables which hold the chain together.
METHODSnewPDF::Builder::Basic::PDF::File->new() Creates a new, empty file object which can act as the
host to other PDF objects. Since there is no file associated with this object,
it is assumed that the object is created in readiness for creating a new PDF
file.
open$p = PDF::Builder::Basic::PDF::File->open($filename, $update, %options) Opens the file and reads all the trailers and cross
reference tables to build a complete directory of objects.
$filename may be a string or an IO object. $update specifies whether this file is being opened for updating and editing (TRUE value), or simply to be read (FALSE or undefined value). %options may include
version$new_version = $p->pdf_version($version, %opts) # Set $ver = $p->pdf_version() # Get Gets/sets the PDF version (e.g., 1.5). Setting sets both
the header and trailer versions. Getting returns the higher of header and
trailer versions.
For compatibility with earlier releases, if no decimal point is given, assume "1." precedes the number given. A warning message is given if you attempt to decrease the PDF version, as you might have already read in a higher level file, or used a higher level feature. This message is suppressed if the 'silent' option is given with any value. header_version$new_version = $p->header_version($version, %opts) # Set $version = $p->header_version() # Get Gets/sets the PDF version stored in the file header.
For compatibility with earlier releases, if no decimal point is given, assume "1." precedes the number given. A warning message is given if you attempt to decrease the PDF version, as you might have already read in a higher level file, or used a higher level feature. This message is suppressed if the 'silent' option is given with any value. trailer_version$new_version = $p->trailer_version($version, %opts) # Set $version = $p->trailer_version() # Get Gets/sets the PDF version stored in the document catalog.
Note that the minimum PDF level for a trailer version is 1.4. It is not permitted to set a PDF level of 1.3 or lower. An existing PDF (read in) of 1.3 or below returns undefined. For compatibility with earlier releases, if no decimal point is given, assume "1." precedes the number given. A warning message is given if you attempt to decrease the PDF version, as you might have already read in a higher level file, or used a higher level feature. This message is suppressed if the 'silent' option is given with any value. require_version$prev_version = $p->require_version($version) Ensures that the PDF version is at least
$version. Silently sets the version to the higher
level.
release$p->release() Releases ALL of the memory used by the PDF document and
all of its component objects. After calling this method, do NOT expect
to have anything left in the
"PDF::Builder::Basic::PDF::File" object (so
if you need to save, be sure to do it before calling this method).
NOTE, that it is important that you call this method on any "PDF::Builder::Basic::PDF::File" object when you wish to destroy it and free up its memory. Internally, PDF files have an enormous number of cross-references, and this causes circular references within the internal data structures. Calling release() causes a brute-force cleanup of the data structures, freeing up all of the memory. Once you've called this method, though, don't expect to be able to do anything else with the "PDF::Builder::Basic::PDF::File" object; it'll have no internal state whatsoever. append_file$p->append_file() Appends the objects for output to the read file and then
appends the appropriate table.
out_file$p->out_file($fname) Writes a PDF file to a file of the given filename, based
on the current list of objects to be output. It creates the trailer dictionary
based on information in $self.
$fname may be a string or an IO object. create_file$p->create_file($fname) Creates a new output file (no check is made of an
existing open file) of the given filename or IO object. Note: make sure that
"$p->{' version'}" is set correctly
before calling this function.
close_file$p->close_file() Closes up the open file for output, by outputting the
trailer, etc.
readval($value, $str) = $p->readval($str, %opts) Reads a PDF value from the current position in the file.
If $str is too short, read some more from the current
location in the file until the whole object is read. This is a recursive call
which may slurp in a whole big stream (unprocessed).
Returns the recursive data structure read and also the current $str that has been read from the file. read_obj$ref = $p->read_obj($objind, %opts) Given an indirect object reference, locate it and read
the object returning the read-in object.
read_objnum$ref = $p->read_objnum($num, $gen, %opts) Returns a fully read object of given number and
generation in this file
new_obj$objind = $p->new_obj($obj) Creates a new, free object reference based on free space
in the cross reference chain. If nothing is free, then think up a new number.
If $obj, then turns that object into this new object
rather than returning a new object.
out_obj$p->out_obj($obj) Indicates that the given object reference should appear
in the output xref table whether with data or freed.
free_obj$p->free_obj($obj) Marks an object reference for output as being
freed.
remove_obj$p->remove_obj($objind) Removes the object from all places where we might
remember it.
ship_out$p->ship_out(@objects) $p->ship_out() Ships the given objects (or all objects for output if
@objects is empty) to the currently open output file
(assuming there is one). Freed objects are not shipped, and once an object is
shipped it is switched such that this file becomes its source and it will not
be shipped again unless out_obj is called again. Notice that a shipped out
object can be re-output or even freed, but that it will not cause the data
already output to be changed.
copy$p->copy($outpdf, \&filter) Iterates over every object in the file reading the
object, calling "filter" with the object,
and outputting the result. If "filter" is
not defined, just copies input to output.
PRIVATE METHODS & FUNCTIONSThe following methods and functions are considered private to this class. This does not mean you cannot use them if you have a need, just that they aren't really designed for users of this class. locate_obj$offset = $p->locate_obj($num, $gen) Returns a file offset to the object asked for by
following the chain of cross reference tables until it finds the one you
want.
updateupdate($fh, $str, $instream) Keeps reading $fh for more data
to ensure that $str has at least a line full for
"readval" to work on. At this point we also
take the opportunity to ignore comments.
test_obj$objind = $p->test_obj($num, $gen) Tests the cache to see whether an object reference (which
may or may not have been getobj()ed) has been cached. Returns it if it
has.
add_obj$p->add_obj($objind) Adds the given object to the internal object cache.
readxrtr$tdict = $p->readxrtr($xpos, %options) Recursive function which reads each of the
cross-reference and trailer tables in turn until there are no more.
Returns a dictionary corresponding to the trailer chain. Each trailer also includes the corresponding cross-reference table. The structure of the xref private element in a trailer dictionary is of an anonymous hash of cross reference elements by object number. Each element consists of an array of 3 elements corresponding to the three elements read in [location, generation number, free or used]. See the PDF specification for details. See "open" for options allowed. out_trailer$p->out_trailer($tdict, $update) $p->out_trailer($tdict) Outputs the body and trailer for a PDF file by outputting
all the objects in the ' outlist' and then outputting a xref table for those
objects and any freed ones. It then outputs the trailing dictionary and the
trailer code.
_newPDF::Builder::Basic::PDF::File->_new() Creates a very empty PDF file object (used by
new() and open())
AUTHORMartin Hosken Martin_Hosken@sil.org Copyright Martin Hosken 1999 No warranty or expression of effectiveness, least of all regarding anyone's safety, is implied in this software or documentation.
|