[gs-cvs] rev 7553 - trunk/gs/lib
ray at ghostscript.com
ray at ghostscript.com
Tue Jan 2 11:58:31 PST 2007
Author: ray
Date: 2007-01-02 11:58:30 -0800 (Tue, 02 Jan 2007)
New Revision: 7553
Modified:
trunk/gs/lib/pdf_main.ps
Log:
Fix for yet another broken PDF that AR handles silently, specifically, a
/Count value of 0 for the Pages tree. When the Count is 0, find the page
count by walking the Pages tree. Bug 689008 for customer 580 and 460.
EXPECTED DIFFERENCES:
None.
Modified: trunk/gs/lib/pdf_main.ps
===================================================================
--- trunk/gs/lib/pdf_main.ps 2007-01-02 15:05:34 UTC (rev 7552)
+++ trunk/gs/lib/pdf_main.ps 2007-01-02 19:58:30 UTC (rev 7553)
@@ -845,6 +845,17 @@
/pdfpagecount % - pdfpagecount <int>
{ Trailer /Root oget /Pages oget
dup /Count knownoget {
+ dup 0 le {
+ pop ( **** Warning: Invalid Page count.\n) pdfformaterror
+ % find the last page and use that as the Count
+ 1 1 999999999 {
+ dup pdffindpage?
+ exch pop
+ //null eq { exit } { pop } ifelse
+ } for
+ 1 sub % decrement to last page that we were able to find
+ 2 copy /Count exch put
+ } if
exch pop
} {
dup /Type oget /Page eq {
@@ -861,10 +872,10 @@
} ifelse
} bind def
-% Find the N'th page of the document by iterating through the Pages tree.
-% The first page is numbered 1.
-/pdffindpageref { % <int> pdffindpage <objref>
- dup Trailer /Root oget /Pages get
+/pdffindpage? { % <int> pdffindpage? 1 null (page not found)
+ % <int> pdffindpage? 1 noderef (page found)
+ % <int> pdffindpage? 0 null (Error: page not found)
+ Trailer /Root oget /Pages get
{ % We should be able to tell when we reach a leaf
% by finding a Type unequal to /Pages. Unfortunately,
% some files distributed by Adobe lack the Type key
@@ -881,6 +892,12 @@
% Stack: index null|noderef
dup null eq { pop pop 1 null exit } if
} loop
+} bind def
+
+% Find the N'th page of the document by iterating through the Pages tree.
+% The first page is numbered 1.
+/pdffindpageref { % <int> pdffindpage <objref>
+ dup pdffindpage?
% Stack: index countleft noderef
1 index 1 ne { pop pop /pdffindpage cvx /rangecheck signalerror } if
exch pop
More information about the gs-cvs
mailing list