1 % Copyright (C) 2001 Aladdin Enterprises. All rights reserved.
3 % This software is provided AS-IS with no warranty, either express or
6 % This software is distributed under license and may not be copied,
7 % modified or distributed except as expressly authorized under the terms
8 % of the license contained in the file LICENSE in this distribution.
10 % For more information about licensing, please refer to
11 % http://www.ghostscript.com/licensing/. For information on
12 % commercial licensing, go to http://www.artifex.com/licensing/ or
13 % contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14 % San Rafael, CA 94903, U.S.A., +1(415)492-9861.
16 % $Id: pphs.ps,v 1.6 2003/08/08 18:45:05 ray Exp $
17 % Print Linearized PDF hint streams
20 /read1 { % <file> read1 <value>
22 (**** Unexpected EOF) = flush quit
25 /read2 { % <file> read2 <value>
26 dup read1 8 bitshift exch read1 add
28 /read4 { % <file> read4 <value>
29 dup read2 16 bitshift exch read2 add
31 % Free variables: Bits, Bitsleft
32 /readninit { % - <readninit> -
37 /pdftoken { % <file> pdftoken <token>
39 dup type /nametype eq 1 index xcheck and {
40 dup dup (<<) cvn eq exch ([) eq or {
42 dup pdftoken dup dup (>>) cvn eq exch (]) eq or {
53 /makemask { % <nbits> makemask <mask>
56 /readn { % <file> <nbits> readn <value>
59 /Bitsleft Bitsleft 2 index sub def
60 makemask Bits Bitsleft neg bitshift and
62 Bitsleft makemask Bits and
63 exch Bitsleft sub exch 1 index bitshift 3 1 roll
64 /Bits 2 index read1 def /Bitsleft 8 def
68 /sread { % <string> sread <file>
69 0 () /SubFileDecode filter
72 /ptag { % <pre-tag> <proc> <post-tag> ptag -
73 3 -1 roll print (: ) print
78 % Print the linearization parameters dictionary.
80 /E (end of p. 1 objects)
81 /L (total file length)
82 /H (PHS start + length)
85 /T (offset of first main xref entry)
87 /plpdict { % <dict> plpdict -
89 2 index 2 index .knownget {
90 % Stack: dict key label value
91 ( ) print 3 -1 roll ===only ( ) print ===only
97 plpkeys 2 index known {
100 ( ) print exch ===only ( ) print ===
105 % Print the Page Offset Hint Table.
106 /ppoht { % <npages> <file> ppoht -
113 (1) { f read4 =only } (least # objs/page) ptag
114 (2) { f read4 =only } (offset of p. 1 object (+PHS length if beyond PHS)) ptag
115 (3) { f read2 dup =only /nb3 exch def } (# bits for # objs/page delta) ptag
116 (4) { f read4 =only } (least # bytes/page) ptag
117 (5) { f read2 dup =only /nb5 exch def } (# bits for # bytes/page delta) ptag
118 (6) { f read4 =only } (least content stream offset-in-page) ptag
119 (7) { f read2 dup =only /nb7 exch def } (# bits for content stream offset delta) ptag
120 (8) { f read4 =only } (least content stream length) ptag
121 (9) { f read2 dup =only /nb9 exch def } (# bits for content stream length delta) ptag
122 (10) { f read2 dup =only /nb10 exch def } (# bits for # of shared obj refs) ptag
123 (11) { f read2 dup =only /nb11 exch def } (# bits for shared obj indices) ptag
124 (12) { f read2 dup =only /nb12 exch def } (# bits for shared obj ref pos numerators) ptag
125 (13) { f read2 =only } (shared obj ref pos denominator) ptag
127 (*1) { [ npages { f nb3 readn } repeat ] ==only } (# objs/page deltas (see 1,3)) ptag
128 (*2) { [ npages { f nb5 readn } repeat ] ==only } (# bytes/page deltas (see 4,5)) ptag
129 (*3) { [ npages { f nb10 readn } repeat ] dup ==only /nso exch def } (# of shared obj refs (see 10)) ptag
130 (*4) { [ nso { [ exch { f nb11 readn } repeat ] } forall ] ==only } (shared obj indices (see 11)) ptag
131 (*5) { [ nso { [ exch { f nb12 readn } repeat ] } forall ] ==only } (shared obj ref pos numerators (see 12)) ptag
132 (*6) { [ npages { f nb7 readn } repeat ] ==only } (content stream offset-in-page deltas (see 6,7)) ptag
133 (*7) { [ npages { f nb9 readn } repeat ] ==only } (content stream length deltas (see 8,9)) ptag
139 % Print the Shared Objects Hint Table.
140 /psoht { % <file> psoht -
146 (1) { f read4 =only } (first shared obj #) ptag
147 (2) { f read4 =only } (first shared obj offset (+PHS length if beyond PHS)) ptag
148 (3) { f read4 dup =only /n3 exch def } (# of p. 1 shared objs) ptag
149 (4) { f read4 dup =only /n4 exch def } (total # of shared objs) ptag
150 (5) { f read2 dup =only /nb5 exch def } (# bits for # of shared objs/group) ptag
151 (6) { f read4 =only } (least shared obj group length) ptag
152 (7) { f read2 dup =only /nb7 exch def } (# bits for shared obj group length delta) ptag
155 (*1) { [ nse { f nb7 readn } repeat ] ==only } (shared obj group length deltas (see 6,7)) ptag
156 (*2) { [ nse { f 1 readn } repeat ] dup ==only /md5s exch def } (MD5 present?) ptag
159 ( ) print f 16 string readstring pop
160 (%stdout) (w) file dup 3 -1 roll writehexstring closefile () =
163 (*4) { [ nse { f nb5 readn } repeat ] ==only } (# objs/group (see 5)) ptag
169 % Print the Primary Hint Stream of a PDF file.
170 /pphs { % <file> pphs -
173 % Read the linearization parameter dictionary.
174 { pdf pdftoken /obj eq { exit } if } loop
175 pdf pdftoken /lpdict exch def
176 /lpdict type /dicttype eq { lpdict /Linearized known } { false } ifelse {
177 (Not a linearized PDF file.) = stop
182 % Read the primary hint stream.
184 pdf pdftoken dup /stream eq { pop exit } if
188 % Remove Length if indirect reference.
190 phsdict 0 undef phsdict /Length undef
192 (PHS: ) print phsdict === flush
193 pdf 0 (endstream) /SubFileDecode filter
194 dup 64000 string readstring pop exch closefile
195 sread /phsdata exch def
197 % Decode the hint stream data if necessary.
198 phsdict /Filter .knownget {
200 dup 5000 string readstring pop exch closefile
201 sread /phsdata exch def
204 % Adobe says we can assume /P = 0.
205 (Page Offset Hint Table:) =
207 phsdata phsdict /S get string readstring pop sread
209 (Shared Objects Hint Table:) =
213 % Check for command line arguments.
216 { 0 get (r) file dup pphs closefile }
217 { (Usage: pphs filename.pdf\n) print flush }