1PDF::Builder::Basic::PDUFs:e:rFiCloen(t3r)ibuted Perl DoPcDuFm:e:nBtuaitlidoenr::Basic::PDF::File(3)
2
3
4

NAME

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

SYNOPSIS

10        $p = PDF::Builder::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::Builder::Basic::PDF::File",
34       the 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
40       use at all, but is included in the documentation for completeness and
41       to 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 override 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.  It 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::Builder::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::Builder::Basic::PDF::File->open($filename, $update, %options)
116       Opens the file and reads all the trailers and cross reference tables to
117       build a complete directory of objects.
118
119       $filename may be a string or an IO object.
120
121       $update specifies whether this file is being opened for updating and
122       editing (TRUE value), or simply to be read (FALSE or undefined value).
123
124       %options may include
125
126       -diags => 1
127           If "-diags" is set to 1, various warning messages will be given if
128           a suspicious PDF structure is found, and some fixup may be
129           attempted. There is no guarantee that any fixup will change the PDF
130           to legitimate, or that there won't be other problems found further
131           down the line. If this flag is not given, and a structural problem
132           is found, it is fairly likely that errors (and even a program
133           crash) may happen further along. If you experience crashes when
134           reading in a PDF file, try running with "-diags" and see what is
135           reported.
136
137           There are many PDF files out "in the wild" which, while failing to
138           conform to Adobe's standards, appear to be tolerated by PDF
139           Readers. Thus, Builder will no longer fail on them, but merely
140           comment on their existence.
141
142   $p->release()
143       Releases ALL of the memory used by the PDF document and all of its
144       component objects.  After calling this method, do NOT expect to have
145       anything left in the "PDF::Builder::Basic::PDF::File" object (so if you
146       need to save, be sure to do it before calling this method).
147
148       NOTE, that it is important that you call this method on any
149       "PDF::Builder::Basic::PDF::File" object when you wish to destroy it and
150       free up its memory.  Internally, PDF files have an enormous number of
151       cross-references, and this causes circular references within the
152       internal data structures. Calling "release()" causes a brute-force
153       cleanup of the data structures, freeing up all of the memory. Once
154       you've called this method, though, don't expect to be able to do
155       anything else with the "PDF::Builder::Basic::PDF::File" object; it'll
156       have no internal state whatsoever.
157
158   $p->append_file()
159       Appends the objects for output to the read file and then appends the
160       appropriate table.
161
162   $p->out_file($fname)
163       Writes a PDF file to a file of the given filename, based on the current
164       list of objects to be output. It creates the trailer dictionary based
165       on information in $self.
166
167       $fname may be a string or an IO object.
168
169   $p->create_file($fname)
170       Creates a new output file (no check is made of an existing open file)
171       of the given filename or IO object. Note: make sure that "$p->{'
172       version'}" is set correctly before calling this function.
173
174   $p->close_file()
175       Closes up the open file for output, by outputting the trailer, etc.
176
177   ($value, $str) = $p->readval($str, %opts)
178       Reads a PDF value from the current position in the file. If $str is too
179       short, read some more from the current location in the file until the
180       whole object is read. This is a recursive call which may slurp in a
181       whole big stream (unprocessed).
182
183       Returns the recursive data structure read and also the current $str
184       that has been read from the file.
185
186   $ref = $p->read_obj($objind, %opts)
187       Given an indirect object reference, locate it and read the object
188       returning the read in object.
189
190   $ref = $p->read_objnum($num, $gen, %opts)
191       Returns a fully read object of given number and generation in this file
192
193   $objind = $p->new_obj($obj)
194       Creates a new, free object reference based on free space in the cross
195       reference chain. If nothing is free, then think up a new number. If
196       $obj, then turns that object into this new object rather than returning
197       a new object.
198
199   $p->out_obj($obj)
200       Indicates that the given object reference should appear in the output
201       xref table whether with data or freed.
202
203   $p->free_obj($obj)
204       Marks an object reference for output as being freed.
205
206   $p->remove_obj($objind)
207       Removes the object from all places where we might remember it.
208
209   $p->ship_out(@objects)
210   $p->ship_out()
211       Ships the given objects (or all objects for output if @objects is
212       empty) to the currently open output file (assuming there is one). Freed
213       objects are not shipped, and once an object is shipped it is switched
214       such that this file becomes its source and it will not be shipped again
215       unless out_obj is called again. Notice that a shipped out object can be
216       re-output or even freed, but that it will not cause the data already
217       output to be changed.
218
219   $p->copy($outpdf, \&filter)
220       Iterates over every object in the file reading the object, calling
221       "filter" with the object, and outputting the result. If "filter" is not
222       defined, just copies input to output.
223

PRIVATE METHODS & FUNCTIONS

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

AUTHOR

271       Martin Hosken Martin_Hosken@sil.org
272
273       Copyright Martin Hosken 1999 and onwards
274
275       No warranty or expression of effectiveness, least of all regarding
276       anyone's safety, is implied in this software or documentation.
277
278
279
280perl v5.34.0                      2021-07-22 PDF::Builder::Basic::PDF::File(3)
Impressum