File: pdfinflt.ps

package info (click to toggle)
ghostscript 8.62.dfsg.1-3.2lenny5
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 55,332 kB
  • ctags: 73,646
  • sloc: ansic: 505,865; sh: 34,002; python: 4,917; cpp: 3,961; asm: 3,565; ada: 1,681; tcl: 1,469; pascal: 1,089; makefile: 885; cs: 879; lisp: 407; xml: 263; perl: 158; awk: 66; yacc: 15
file content (167 lines) | stat: -rw-r--r-- 4,920 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
%    Copyright (C) 1992, 1993, 1994, 1995, 1999 Aladdin Enterprises.  All rights reserved.
% 
% This software is provided AS-IS with no warranty, either express or
% implied.
% 
% This software is distributed under license and may not be copied,
% modified or distributed except as expressly authorized under the terms
% of the license contained in the file LICENSE in this distribution.
% 
% For more information about licensing, please refer to
% http://www.ghostscript.com/licensing/. For information on
% commercial licensing, go to http://www.artifex.com/licensing/ or
% contact Artifex Software, Inc., 101 Lucas Valley Road #110,
% San Rafael, CA  94903, U.S.A., +1(415)492-9861.

% $Id: pdfinflt.ps 7061 2006-09-20 12:01:04Z leonardo $
% pdfinflt.ps
% 
% Try to decompress any FlateDecode streams in the input file.
% 
% Usage: gs -- toolbin/pdfinflt.ps infile outfile
%
% Requires: lib/pdfwrite.ps.
% 
% 
% It is not yet ready for prime time, but it is available for anyone wants
% to fix it.
% 
% The main problem is:
% 
% 1. Sometimes the PDF files that are written are broken. When they are
%    broken, GS gets an xref problem.
% 
%    This problem is actually due to lib/pdfwrite.ps since even
%    when no conversion is done, the file is may be bad.

% Check to make sure both input and output filename was specified.
[ shellarguments
  { counttomark 2 eq {
      % Arguments ok
      /OutFileName exch def
      /InFileName exch def
   
      (pdfwrite.ps) runlibfile
   
      /justcopy /pdfcopystream load def
      /filterstoremove <<
	  % list of filters to apply
	  %   - kept as a dictionary, for faster searches
	  %   - the corresponding value is currently unused
	  /ASCIIHexDecode   null
	  /ASCII85Decode    null
	  /LZWDecode	    null
	  /FlateDecode	    null
	% /RunLengthDecode  null
	% /CCITTFaxDecode   null
	% /DCTDecode	    null
	% /JBIG2Decode	    dup /Filter resourcestatus {pop pop (GS-specific)} {pop} ifelse
	% /JPXDecode	    dup /Filter resourcestatus {pop pop (GS-specific)} {pop} ifelse
	% /Crypt	    (no equivalent)
	>> def
      /pdfcopystream {		% <newstreamdict> <file> pdfcopystream -
				%   (file has been positioned)
	1 index /Filter known {
            10 dict begin
		%stack: <newstreamdict> <file>
		/infile exch def /sdict exch def
		RMap ld_length neg omapnew pop /lenobj exch def
		/copyofsdict sdict dup length dict copy def
		copyofsdict dup /Length lenobj /O cvx 2 packedarray cvx put
		infile sdict /Length oget () /SubFileDecode filter
		% apply filters to the (input) stream
		{
		    %stack: <file>
		    % extract first filter and its parameters
		    {/DecodeParms/Filter} {
			copyofsdict exch knownoget {
			    dup type /arraytype eq { 0 get } if
			} {
			    null
			} ifelse
		    } forall
		    %stack: <file> <decode|null> <filter|null>
		    dup null eq {
		      pop pop exit
		    } if
		    filterstoremove 1 index known {
			% apply the filter
			exch dup null eq { pop } { exch } ifelse
			filter
			%stack: <file>
			% remove first element from each of /Filter and /DecodeParms
			copyofsdict dup {/DecodeParms/Filter} {
			    %stack: <file> <copyofsdict> <copyofsdict> </Key>
			    2 copy knownoget {
				dup type /arraytype eq {
				    dup length dup 3 ge {
					1 exch 1 sub getinterval put
				    } {
					{
					    {pop undef}	    % []
					    {pop undef}	    % [elem]
					    {1 get put}	    % [elem1 elem2]
					} exch get exec
				    } ifelse
				} {
				    pop undef
				} ifelse
				dup
			    } {
				pop
			    } ifelse
			} forall pop pop
		    } {
			pop pop exit
		    } ifelse
		} loop
		/infile exch def
		copyofsdict pdfwritevalue (stream\n) ows
		/opos OFile fileposition def
		infile dup OFile 16#7fffffff pdfcopybytes closefile
		/len OFile fileposition opos sub def
		(\nendstream\nendobj\n) ows
		lenobj pdfwriteobjheader len pdfwritevalue
	    end	    
	} {
	    justcopy
	} ifelse
      } def
   
      { InFileName (r) file } stopped
      { (\n*** Cannot open input file: ) print InFileName print ( ***\n\n) print flush
        quit
      }
      if
      pdfdict begin pdfopen begin
      
      { OutFileName (w) file } stopped
      { (\n*** Cannot open output file: ) print OutFileName print ( ***\n\n) print flush
        quit
      }
      if
      (Converting ) print InFileName print ( to ) print OutFileName = flush
      currentdict /Trailer get
      dup /Prev undef		% We don't want a 'Prev' link.
      pdfwrite
      end end
      (Done.\n) print flush
      cleartomark
      true		% success
    }
    {
      (\n*** Incorrect number of file name arguments. ***\n\n) print
      cleartomark false			% incorrect number of arguments
    }
    ifelse
  }
  {
    (\n*** Missing '--' preceding toolbin/pdfinflt.ps ***\n\n) print
    cleartomark false			% not in shell arguments mode (missing -- )
  }
ifelse 
not {
   (Usage: gs -- toolbin/pdfinflt.ps infile outfile\n\n) print flush
}
if
quit