1PDF::API2::Basic::PDF::UFsielre(C3o)ntributed Perl DocumPeDnFt:a:tAiPoIn2::Basic::PDF::File(3)
2
3
4
6 PDF::API2::Basic::PDF::File - Holds the trailers and cross-reference
7 tables for a PDF file
8
10 $p = PDF::API2::Basic::PDF::File->open("filename.pdf", 1);
11 $p->new_obj($obj_ref);
12 $p->free_obj($obj_ref);
13 $p->append_file;
14 $p->close_file;
15 $p->release; # IMPORTANT!
16
18 This class keeps track of the directory aspects of a PDF file. There
19 are two parts to the directory: the main directory object which is the
20 parent to all other objects and a chain of cross-reference tables and
21 corresponding trailer dictionaries starting with the main directory
22 object.
23
25 Within this class hierarchy, rather than making everything visible via
26 methods, which would be a lot of work, there are various instance
27 variables which are accessible via associative array referencing. To
28 distinguish instance variables from content variables (which may come
29 from the PDF content itself), each such variable will start with a
30 space.
31
32 Variables which do not start with a space directly reflect elements in
33 a PDF dictionary. In the case of a PDF::API2::Basic::PDF::File, the
34 elements reflect those in the trailer dictionary.
35
36 Since some variables are not designed for class users to access,
37 variables are marked in the documentation with (R) to indicate that
38 such an entry should only be used as read-only information. (P)
39 indicates that the information is private and not designed for user use
40 at all, but is included in the documentation for completeness and to
41 ensure that nobody else tries to use it.
42
43 newroot
44 This variable allows the user to create a new root entry to occur
45 in the trailer dictionary which is output when the file is written
46 or appended. If you wish to over-ride the root element in the
47 dictionary you have, use this entry to indicate that without losing
48 the current Root entry. Notice that newroot should point to a PDF
49 level object and not just to a dictionary which does not have
50 object status.
51
52 INFILE (R)
53 Contains the filehandle used to read this information into this PDF
54 directory. Is an IO object.
55
56 fname (R)
57 This is the filename which is reflected by INFILE, or the original
58 IO object passed in.
59
60 update (R)
61 This indicates that the read file has been opened for update and
62 that at some point, $p->appendfile() can be called to update the
63 file with the changes that have been made to the memory
64 representation.
65
66 maxobj (R)
67 Contains the first useable object number above any that have
68 already appeared in the file so far.
69
70 outlist (P)
71 This is a list of Objind which are to be output when the next
72 appendfile or outfile occurs.
73
74 firstfree (P)
75 Contains the first free object in the free object list. Free
76 objects are removed from the front of the list and added to the
77 end.
78
79 lastfree (P)
80 Contains the last free object in the free list. It may be the same
81 as the firstfree if there is only one free object.
82
83 objcache (P)
84 All objects are held in the cache to ensure that a system only has
85 one occurrence of each object. In effect, the objind class acts as
86 a container type class to hold the PDF object structure and it
87 would be unfortunate if there were two identical place-holders
88 floating around a system.
89
90 epos (P)
91 The end location of the read-file.
92
93 Each trailer dictionary contains a number of private instance variables
94 which hold the chain together.
95
96 loc (P)
97 Contains the location of the start of the cross-reference table
98 preceding the trailer.
99
100 xref (P)
101 Contains an anonymous array of each cross-reference table entry.
102
103 prev (P)
104 A reference to the previous table. Note this differs from the Prev
105 entry which is in PDF which contains the location of the previous
106 cross-reference table.
107
109 PDF::API2::Basic::PDF::File->new
110 Creates a new, empty file object which can act as the host to other PDF
111 objects. Since there is no file associated with this object, it is
112 assumed that the object is created in readiness for creating a new PDF
113 file.
114
115 $p = PDF::API2::Basic::PDF::File->open($filename, $update)
116 Opens the file and reads all the trailers and cross reference tables to
117 build a complete directory of objects.
118
119 $update specifies whether this file is being opened for updating and
120 editing, or simply to be read.
121
122 $filename may be an IO object
123
124 $p->release()
125 Releases ALL of the memory used by the PDF document and all of its
126 component objects. After calling this method, do NOT expect to have
127 anything left in the "PDF::API2::Basic::PDF::File" object (so if you
128 need to save, be sure to do it before calling this method).
129
130 NOTE, that it is important that you call this method on any
131 "PDF::API2::Basic::PDF::File" object when you wish to destruct it and
132 free up its memory. Internally, PDF files have an enormous number of
133 cross-references and this causes circular references within the
134 internal data structures. Calling '"release()"' forces a brute-force
135 cleanup of the data structures, freeing up all of the memory. Once
136 you've called this method, though, don't expect to be able to do
137 anything else with the "PDF::API2::Basic::PDF::File" object; it'll have
138 no internal state whatsoever.
139
140 Developer note: As part of the brute-force cleanup done here, this
141 method will throw a warning message whenever unexpected key values are
142 found within the "PDF::API2::Basic::PDF::File" object. This is done to
143 help ensure that any unexpected and unfreed values are brought to your
144 attention so that you can bug us to keep the module updated properly;
145 otherwise the potential for memory leaks due to dangling circular
146 references will exist.
147
148 $p->append_file()
149 Appends the objects for output to the read file and then appends the
150 appropriate tale.
151
152 $p->out_file($fname)
153 Writes a PDF file to a file of the given filename based on the current
154 list of objects to be output. It creates the trailer dictionary based
155 on information in $self.
156
157 $fname may be an IO object;
158
159 $p->create_file($fname)
160 Creates a new output file (no check is made of an existing open file)
161 of the given filename or IO object. Note, make sure that $p->{'
162 version'} is set correctly before calling this function.
163
164 $p->close_file
165 Closes up the open file for output by outputting the trailer etc.
166
167 ($value, $str) = $p->readval($str, %opts)
168 Reads a PDF value from the current position in the file. If $str is too
169 short then read some more from the current location in the file until
170 the whole object is read. This is a recursive call which may slurp in a
171 whole big stream (unprocessed).
172
173 Returns the recursive data structure read and also the current $str
174 that has been read from the file.
175
176 $ref = $p->read_obj($objind, %opts)
177 Given an indirect object reference, locate it and read the object
178 returning the read in object.
179
180 $ref = $p->read_objnum($num, $gen, %opts)
181 Returns a fully read object of given number and generation in this file
182
183 $objind = $p->new_obj($obj)
184 Creates a new, free object reference based on free space in the cross
185 reference chain. If nothing free then thinks up a new number. If $obj
186 then turns that object into this new object rather than returning a new
187 object.
188
189 $p->out_obj($objind)
190 Indicates that the given object reference should appear in the output
191 xref table whether with data or freed.
192
193 $p->free_obj($objind)
194 Marks an object reference for output as being freed.
195
196 $p->remove_obj($objind)
197 Removes the object from all places where we might remember it
198
199 $p->ship_out(@objects)
200 Ships the given objects (or all objects for output if @objects is
201 empty) to the currently open output file (assuming there is one). Freed
202 objects are not shipped, and once an object is shipped it is switched
203 such that this file becomes its source and it will not be shipped again
204 unless out_obj is called again. Notice that a shipped out object can be
205 re-output or even freed, but that it will not cause the data already
206 output to be changed.
207
208 $p->copy($outpdf, \&filter)
209 Iterates over every object in the file reading the object, calling
210 filter with the object and outputting the result. if filter is not
211 defined, then just copies input to output.
212
214 The following methods and functions are considered private to this
215 class. This does not mean you cannot use them if you have a need, just
216 that they aren't really designed for users of this class.
217
218 $offset = $p->locate_obj($num, $gen)
219 Returns a file offset to the object asked for by following the chain of
220 cross reference tables until it finds the one you want.
221
222 update($fh, $str, $instream)
223 Keeps reading $fh for more data to ensure that $str has at least a line
224 full for "readval" to work on. At this point we also take the
225 opportunity to ignore comments.
226
227 $objind = $p->test_obj($num, $gen)
228 Tests the cache to see whether an object reference (which may or may
229 not have been getobj()ed) has been cached. Returns it if it has.
230
231 $p->add_obj($objind)
232 Adds the given object to the internal object cache.
233
234 $tdict = $p->readxrtr($xpos)
235 Recursive function which reads each of the cross-reference and trailer
236 tables in turn until there are no more.
237
238 Returns a dictionary corresponding to the trailer chain. Each trailer
239 also includes the corresponding cross-reference table.
240
241 The structure of the xref private element in a trailer dictionary is of
242 an anonymous hash of cross reference elements by object number. Each
243 element consists of an array of 3 elements corresponding to the three
244 elements read in [location, generation number, free or used]. See the
245 PDF Specification for details.
246
247 $p->out_trailer($tdict)
248 Outputs the body and trailer for a PDF file by outputting all the
249 objects in the ' outlist' and then outputting a xref table for those
250 objects and any freed ones. It then outputs the trailing dictionary and
251 the trailer code.
252
253 PDF::API2::Basic::PDF::File->_new
254 Creates a very empty PDF file object (used by new and open)
255
257 Martin Hosken Martin_Hosken@sil.org
258
259 Copyright Martin Hosken 1999 and onwards
260
261 No warranty or expression of effectiveness, least of all regarding
262 anyone's safety, is implied in this software or documentation.
263
264 Licensing
265 This Perl Text::PDF module is licensed under the Perl Artistic License.
266
267
268
269perl v5.12.2 2011-01-24 PDF::API2::Basic::PDF::File(3)