.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "PDF::Builder::Basic::PDF::File 3pm" .TH PDF::Builder::Basic::PDF::File 3pm "2021-03-28" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" PDF::Builder::Basic::PDF::File \- Holds the trailers and cross\-reference tables for a PDF file .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 6 \& $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! .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This class keeps track of the directory aspects of a \s-1PDF\s0 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. .SH "INSTANCE VARIABLES" .IX Header "INSTANCE VARIABLES" Within 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 \s-1PDF\s0 content itself), each such variable will start with a space. .PP Variables which do not start with a space directly reflect elements in a \s-1PDF\s0 dictionary. In the case of a \f(CW\*(C`PDF::Builder::Basic::PDF::File\*(C'\fR, the elements reflect those in the trailer dictionary. .PP Since some variables are not designed for class users to access, variables are marked in the documentation with \fB(R)\fR to indicate that such an entry should only be used as \fBread-only\fR information. \fB(P)\fR indicates that the information is \fBprivate\fR, 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. .IP "newroot" 4 .IX Item "newroot" This variable allows the user to create a new root entry to occur in the trailer dictionary which is output when the file is written or appended. If you wish to override the root element in the dictionary you have, use this entry to indicate that without losing the current Root entry. Notice that newroot should point to a \s-1PDF\s0 level object and not just to a dictionary which does not have object status. .IP "\s-1INFILE\s0 (R)" 4 .IX Item "INFILE (R)" Contains the filehandle used to read this information into this \s-1PDF\s0 directory. It is an \s-1IO\s0 object. .IP "fname (R)" 4 .IX Item "fname (R)" This is the filename which is reflected by \s-1INFILE,\s0 or the original \s-1IO\s0 object passed in. .IP "update (R)" 4 .IX Item "update (R)" This indicates that the read file has been opened for update and that at some point, \f(CW\*(C`$p\->appendfile()\*(C'\fR can be called to update the file with the changes that have been made to the memory representation. .IP "maxobj (R)" 4 .IX Item "maxobj (R)" Contains the first usable object number above any that have already appeared in the file so far. .IP "outlist (P)" 4 .IX Item "outlist (P)" This is a list of Objind which are to be output when the next \f(CW\*(C`appendfile()\*(C'\fR or \f(CW\*(C`outfile()\*(C'\fR occurs. .IP "firstfree (P)" 4 .IX Item "firstfree (P)" Contains the first free object in the free object list. Free objects are removed from the front of the list and added to the end. .IP "lastfree (P)" 4 .IX Item "lastfree (P)" Contains the last free object in the free list. It may be the same as the \&\f(CW\*(C`firstfree\*(C'\fR if there is only one free object. .IP "objcache (P)" 4 .IX Item "objcache (P)" All objects are held in the cache to ensure that a system only has one occurrence of each object. In effect, the objind class acts as a container type class to hold the \s-1PDF\s0 object structure, and it would be unfortunate if there were two identical place-holders floating around a system. .IP "epos (P)" 4 .IX Item "epos (P)" The end location of the read-file. .PP Each trailer dictionary contains a number of private instance variables which hold the chain together. .IP "loc (P)" 4 .IX Item "loc (P)" Contains the location of the start of the cross-reference table preceding the trailer. .IP "xref (P)" 4 .IX Item "xref (P)" Contains an anonymous array of each cross-reference table entry. .IP "prev (P)" 4 .IX Item "prev (P)" A reference to the previous table. Note this differs from the Prev entry which is in \s-1PDF,\s0 which contains the location of the previous cross-reference table. .SH "METHODS" .IX Header "METHODS" .SS "PDF::Builder::Basic::PDF::File\->\fBnew()\fP" .IX Subsection "PDF::Builder::Basic::PDF::File->new()" Creates a new, empty file object which can act as the host to other \s-1PDF\s0 objects. Since there is no file associated with this object, it is assumed that the object is created in readiness for creating a new \s-1PDF\s0 file. .ie n .SS "$p = PDF::Builder::Basic::PDF::File\->open($filename, $update, %options)" .el .SS "\f(CW$p\fP = PDF::Builder::Basic::PDF::File\->open($filename, \f(CW$update\fP, \f(CW%options\fP)" .IX Subsection "$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. .PP \&\f(CW$filename\fR may be a string or an \s-1IO\s0 object. .PP \&\f(CW$update\fR specifies whether this file is being opened for updating and editing (\fI\s-1TRUE\s0\fR value), or simply to be read (\fI\s-1FALSE\s0\fR or undefined value). .PP \&\f(CW%options\fR may include .IP "\-diags => 1" 4 .IX Item "-diags => 1" If \f(CW\*(C`\-diags\*(C'\fR is set to 1, various warning messages will be given if a suspicious \s-1PDF\s0 structure is found, and some fixup may be attempted. There is no guarantee that any fixup will change the \s-1PDF\s0 to legitimate, or that there won't be other problems found further down the line. If this flag is \fInot\fR given, and a structural problem is found, it is fairly likely that errors (and even a program \fBcrash\fR) may happen further along. If you experience crashes when reading in a \s-1PDF\s0 file, try running with \f(CW\*(C`\-diags\*(C'\fR and see what is reported. .Sp There are many \s-1PDF\s0 files out \*(L"in the wild\*(R" which, while failing to conform to Adobe's standards, appear to be tolerated by \s-1PDF\s0 Readers. Thus, Builder will no longer fail on them, but merely comment on their existence. .ie n .SS "$p\->\fBrelease()\fP" .el .SS "\f(CW$p\fP\->\fBrelease()\fP" .IX Subsection "$p->release()" Releases \s-1ALL\s0 of the memory used by the \s-1PDF\s0 document and all of its component objects. After calling this method, do \fB\s-1NOT\s0\fR expect to have anything left in the \f(CW\*(C`PDF::Builder::Basic::PDF::File\*(C'\fR object (so if you need to save, be sure to do it before calling this method). .PP \&\fB\s-1NOTE\s0\fR, that it is important that you call this method on any \&\f(CW\*(C`PDF::Builder::Basic::PDF::File\*(C'\fR object when you wish to destroy it and free up its memory. Internally, \s-1PDF\s0 files have an enormous number of cross-references, and this causes circular references within the internal data structures. Calling \f(CW\*(C`release()\*(C'\fR 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 \f(CW\*(C`PDF::Builder::Basic::PDF::File\*(C'\fR object; it'll have \fBno\fR internal state whatsoever. .ie n .SS "$p\->\fBappend_file()\fP" .el .SS "\f(CW$p\fP\->\fBappend_file()\fP" .IX Subsection "$p->append_file()" Appends the objects for output to the read file and then appends the appropriate table. .ie n .SS "$p\->out_file($fname)" .el .SS "\f(CW$p\fP\->out_file($fname)" .IX Subsection "$p->out_file($fname)" Writes a \s-1PDF\s0 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 \f(CW$self\fR. .PP \&\f(CW$fname\fR may be a string or an \s-1IO\s0 object. .ie n .SS "$p\->create_file($fname)" .el .SS "\f(CW$p\fP\->create_file($fname)" .IX Subsection "$p->create_file($fname)" Creates a new output file (no check is made of an existing open file) of the given filename or \s-1IO\s0 object. Note: make sure that \f(CW\*(C`$p\->{\*(Aq version\*(Aq}\*(C'\fR is set correctly before calling this function. .ie n .SS "$p\->\fBclose_file()\fP" .el .SS "\f(CW$p\fP\->\fBclose_file()\fP" .IX Subsection "$p->close_file()" Closes up the open file for output, by outputting the trailer, etc. .ie n .SS "($value, $str) = $p\->readval($str, %opts)" .el .SS "($value, \f(CW$str\fP) = \f(CW$p\fP\->readval($str, \f(CW%opts\fP)" .IX Subsection "($value, $str) = $p->readval($str, %opts)" Reads a \s-1PDF\s0 value from the current position in the file. If \f(CW$str\fR 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). .PP Returns the recursive data structure read and also the current \f(CW$str\fR that has been read from the file. .ie n .SS "$ref = $p\->read_obj($objind, %opts)" .el .SS "\f(CW$ref\fP = \f(CW$p\fP\->read_obj($objind, \f(CW%opts\fP)" .IX Subsection "$ref = $p->read_obj($objind, %opts)" Given an indirect object reference, locate it and read the object returning the read in object. .ie n .SS "$ref = $p\->read_objnum($num, $gen, %opts)" .el .SS "\f(CW$ref\fP = \f(CW$p\fP\->read_objnum($num, \f(CW$gen\fP, \f(CW%opts\fP)" .IX Subsection "$ref = $p->read_objnum($num, $gen, %opts)" Returns a fully read object of given number and generation in this file .ie n .SS "$objind = $p\->new_obj($obj)" .el .SS "\f(CW$objind\fP = \f(CW$p\fP\->new_obj($obj)" .IX Subsection "$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 \f(CW$obj\fR, then turns that object into this new object rather than returning a new object. .ie n .SS "$p\->out_obj($obj)" .el .SS "\f(CW$p\fP\->out_obj($obj)" .IX Subsection "$p->out_obj($obj)" Indicates that the given object reference should appear in the output xref table whether with data or freed. .ie n .SS "$p\->free_obj($obj)" .el .SS "\f(CW$p\fP\->free_obj($obj)" .IX Subsection "$p->free_obj($obj)" Marks an object reference for output as being freed. .ie n .SS "$p\->remove_obj($objind)" .el .SS "\f(CW$p\fP\->remove_obj($objind)" .IX Subsection "$p->remove_obj($objind)" Removes the object from all places where we might remember it. .ie n .SS "$p\->ship_out(@objects)" .el .SS "\f(CW$p\fP\->ship_out(@objects)" .IX Subsection "$p->ship_out(@objects)" .ie n .SS "$p\->\fBship_out()\fP" .el .SS "\f(CW$p\fP\->\fBship_out()\fP" .IX Subsection "$p->ship_out()" Ships the given objects (or all objects for output if \f(CW@objects\fR 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. .ie n .SS "$p\->copy($outpdf, \e&filter)" .el .SS "\f(CW$p\fP\->copy($outpdf, \e&filter)" .IX Subsection "$p->copy($outpdf, &filter)" Iterates over every object in the file reading the object, calling \f(CW\*(C`filter\*(C'\fR with the object, and outputting the result. If \f(CW\*(C`filter\*(C'\fR is not defined, just copies input to output. .SH "PRIVATE METHODS & FUNCTIONS" .IX Header "PRIVATE METHODS & FUNCTIONS" The following methods and functions are considered \fBprivate\fR 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. .ie n .SS "$offset = $p\->locate_obj($num, $gen)" .el .SS "\f(CW$offset\fP = \f(CW$p\fP\->locate_obj($num, \f(CW$gen\fP)" .IX Subsection "$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. .ie n .SS "update($fh, $str, $instream)" .el .SS "update($fh, \f(CW$str\fP, \f(CW$instream\fP)" .IX Subsection "update($fh, $str, $instream)" Keeps reading \f(CW$fh\fR for more data to ensure that \f(CW$str\fR has at least a line full for \f(CW\*(C`readval\*(C'\fR to work on. At this point we also take the opportunity to ignore comments. .ie n .SS "$objind = $p\->test_obj($num, $gen)" .el .SS "\f(CW$objind\fP = \f(CW$p\fP\->test_obj($num, \f(CW$gen\fP)" .IX Subsection "$objind = $p->test_obj($num, $gen)" Tests the cache to see whether an object reference (which may or may not have been \fBgetobj()\fRed) has been cached. Returns it if it has. .ie n .SS "$p\->add_obj($objind)" .el .SS "\f(CW$p\fP\->add_obj($objind)" .IX Subsection "$p->add_obj($objind)" Adds the given object to the internal object cache. .ie n .SS "$tdict = $p\->readxrtr($xpos, %options)" .el .SS "\f(CW$tdict\fP = \f(CW$p\fP\->readxrtr($xpos, \f(CW%options\fP)" .IX Subsection "$tdict = $p->readxrtr($xpos, %options)" Recursive function which reads each of the cross-reference and trailer tables in turn until there are no more. .PP Returns a dictionary corresponding to the trailer chain. Each trailer also includes the corresponding cross-reference table. .PP 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 \s-1PDF\s0 specification for details. .PP See \f(CW\*(C`open\*(C'\fR for options allowed. .ie n .SS "$p\->out_trailer($tdict, $update)" .el .SS "\f(CW$p\fP\->out_trailer($tdict, \f(CW$update\fP)" .IX Subsection "$p->out_trailer($tdict, $update)" .ie n .SS "$p\->out_trailer($tdict)" .el .SS "\f(CW$p\fP\->out_trailer($tdict)" .IX Subsection "$p->out_trailer($tdict)" Outputs the body and trailer for a \s-1PDF\s0 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. .SS "PDF::Builder::Basic::PDF::File\->\fB_new()\fP" .IX Subsection "PDF::Builder::Basic::PDF::File->_new()" Creates a very empty \s-1PDF\s0 file object (used by \fBnew()\fR and \fBopen()\fR) .SH "AUTHOR" .IX Header "AUTHOR" Martin Hosken Martin_Hosken@sil.org .PP Copyright Martin Hosken 1999 and onwards .PP No warranty or expression of effectiveness, least of all regarding anyone's safety, is implied in this software or documentation.