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->close_file
157       Closes up the open file for output by outputting the trailer etc.
158
159   ($value, $str) = $p->readval($str, %opts)
160       Reads a PDF value from the current position in the file. If $str is too
161       short then read some more from the current location in the file until
162       the whole object is read. This is a recursive call which may slurp in a
163       whole big stream (unprocessed).
164
165       Returns the recursive data structure read and also the current $str
166       that has been read from the file.
167
168   $ref = $p->read_obj($objind, %opts)
169       Given an indirect object reference, locate it and read the object
170       returning the read in object.
171
172   $ref = $p->read_objnum($num, $gen, %opts)
173       Returns a fully read object of given number and generation in this file
174
175   $objind = $p->new_obj($obj)
176       Creates a new, free object reference based on free space in the cross
177       reference chain.  If nothing free then thinks up a new number. If $obj
178       then turns that object into this new object rather than returning a new
179       object.
180
181   $p->out_obj($objind)
182       Indicates that the given object reference should appear in the output
183       xref table whether with data or freed.
184
185   $p->free_obj($objind)
186       Marks an object reference for output as being freed.
187
188   $p->remove_obj($objind)
189       Removes the object from all places where we might remember it
190
191   $p->ship_out(@objects)
192       Ships the given objects (or all objects for output if @objects is
193       empty) to the currently open output file (assuming there is one). Freed
194       objects are not shipped, and once an object is shipped it is switched
195       such that this file becomes its source and it will not be shipped again
196       unless out_obj is called again. Notice that a shipped out object can be
197       re-output or even freed, but that it will not cause the data already
198       output to be changed.
199
200   $p->copy($outpdf, \&filter)
201       Iterates over every object in the file reading the object, calling
202       filter with the object and outputting the result. if filter is not
203       defined, then just copies input to output.
204

PRIVATE METHODS & FUNCTIONS

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

AUTHOR

249       Martin Hosken Martin_Hosken@sil.org
250
251       Copyright Martin Hosken 1999 and onwards
252
253       No warranty or expression of effectiveness, least of all regarding
254       anyone's safety, is implied in this software or documentation.
255
256
257
258perl v5.32.0                      2020-07-28    PDF::API2::Basic::PDF::File(3)
Impressum