1PDF::API2::Basic::PDF::UFsielre(C3o)ntributed Perl DocumPeDnFt:a:tAiPoIn2::Basic::PDF::File(3)
2
3
4

NAME

6       PDF::API2::Basic::PDF::File - Holds the trailers and cross-reference
7       tables for a PDF file
8

SYNOPSIS

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

DESCRIPTION

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

INSTANCE VARIABLES

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 usable object number above any that have already
68           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

METHODS

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   $p->append_file()
141       Appends the objects for output to the read file and then appends the
142       appropriate table.
143
144   $p->out_file($fname)
145       Writes a PDF file to a file of the given filename based on the current
146       list of objects to be output. It creates the trailer dictionary based
147       on information in $self.
148
149       $fname may be an IO object;
150
151   $p->create_file($fname)
152       Creates a new output file (no check is made of an existing open file)
153       of the given filename or IO object. Note, make sure that $p->{'
154       version'} is set correctly before calling this function.
155
156   $p->clone_file($fname)
157       Creates a copy of the input file at the specified filename and sets it
158       as the output file for future writes.  A file handle may be passed
159       instead of a filename.
160
161   $p->close_file
162       Closes up the open file for output by outputting the trailer etc.
163
164   ($value, $str) = $p->readval($str, %opts)
165       Reads a PDF value from the current position in the file. If $str is too
166       short then read some more from the current location in the file until
167       the whole object is read. This is a recursive call which may slurp in a
168       whole big stream (unprocessed).
169
170       Returns the recursive data structure read and also the current $str
171       that has been read from the file.
172
173   $ref = $p->read_obj($objind, %opts)
174       Given an indirect object reference, locate it and read the object
175       returning the read in object.
176
177   $ref = $p->read_objnum($num, $gen, %opts)
178       Returns a fully read object of given number and generation in this file
179
180   $objind = $p->new_obj($obj)
181       Creates a new, free object reference based on free space in the cross
182       reference chain.  If nothing free then thinks up a new number. If $obj
183       then turns that object into this new object rather than returning a new
184       object.
185
186   $p->out_obj($objind)
187       Indicates that the given object reference should appear in the output
188       xref table whether with data or freed.
189
190   $p->free_obj($objind)
191       Marks an object reference for output as being freed.
192
193   $p->remove_obj($objind)
194       Removes the object from all places where we might remember it
195
196   $p->ship_out(@objects)
197       Ships the given objects (or all objects for output if @objects is
198       empty) to the currently open output file (assuming there is one). Freed
199       objects are not shipped, and once an object is shipped it is switched
200       such that this file becomes its source and it will not be shipped again
201       unless out_obj is called again. Notice that a shipped out object can be
202       re-output or even freed, but that it will not cause the data already
203       output to be changed.
204
205   $p->copy($outpdf, \&filter)
206       Iterates over every object in the file reading the object, calling
207       filter with the object and outputting the result. if filter is not
208       defined, then just copies input to output.
209

PRIVATE METHODS & FUNCTIONS

211       The following methods and functions are considered private to this
212       class. This does not mean you cannot use them if you have a need, just
213       that they aren't really designed for users of this class.
214
215   $offset = $p->locate_obj($num, $gen)
216       Returns a file offset to the object asked for by following the chain of
217       cross reference tables until it finds the one you want.
218
219   update($fh, $str, $instream)
220       Keeps reading $fh for more data to ensure that $str has at least a line
221       full for "readval" to work on. At this point we also take the
222       opportunity to ignore comments.
223
224   $objind = $p->test_obj($num, $gen)
225       Tests the cache to see whether an object reference (which may or may
226       not have been getobj()ed) has been cached. Returns it if it has.
227
228   $p->add_obj($objind)
229       Adds the given object to the internal object cache.
230
231   $tdict = $p->readxrtr($xpos)
232       Recursive function which reads each of the cross-reference and trailer
233       tables in turn until there are no more.
234
235       Returns a dictionary corresponding to the trailer chain. Each trailer
236       also includes the corresponding cross-reference table.
237
238       The structure of the xref private element in a trailer dictionary is of
239       an anonymous hash of cross reference elements by object number. Each
240       element consists of an array of 3 elements corresponding to the three
241       elements read in [location, generation number, free or used]. See the
242       PDF specification for details.
243
244   $p->out_trailer($tdict)
245       Outputs the body and trailer for a PDF file by outputting all the
246       objects in the ' outlist' and then outputting a xref table for those
247       objects and any freed ones. It then outputs the trailing dictionary and
248       the trailer code.
249
250   PDF::API2::Basic::PDF::File->_new
251       Creates a very empty PDF file object (used by new and open)
252

AUTHOR

254       Martin Hosken Martin_Hosken@sil.org
255
256       Copyright Martin Hosken 1999 and onwards
257
258       No warranty or expression of effectiveness, least of all regarding
259       anyone's safety, is implied in this software or documentation.
260
261
262
263perl v5.34.0                      2021-08-02    PDF::API2::Basic::PDF::File(3)
Impressum