[gs-code-review] Impossible to rewrite pdf files with named action
"LastPage" , bug 688311)
Heiko Oberdiek
oberdiek at uni-freiburg.de
Thu Sep 22 08:41:50 PDT 2005
Hello,
the description on http://www.ghostscript.com/ or
http://bugs.ghostscript.com/bugwritinghelp.html was not clear
for me, how to attach files or send patches.
Thus I have attachted a test file test.pdf and a fix
pdf_main.ps.diff for bug report 688311. I hope, this list
is the right place for this.
Walter Schmidt send me a problem with pdf files that use the named
action "LastPage". The following fails:
gs -sDEVICE=pdfwrite -dBATCH -dNOPAUSE -sOutputFile=t.pdf test.pdf
Processing pages 1 through 1.
Page 1
Error: /rangecheck in --pdfmark--
Operand stack:
--dict:6/6(L)-- --nostringval-- --nostringval-- Rect
--nostringval-- --dict:4/4(L)-- Page 1 LNK
Execution stack:
%interp_exit .runexec2 --nostringval-- --nostringval--
--nostringval-- 2 %stopped_push --nostringval-- --nostringval--
--nostringval-- false 1 %stopped_push
1 3 %oparray_pop 1 3 %oparray_pop 1 3 %oparray_pop
--nostringval-- --nostringval-- 2 1 1 --nostringval--
%for_pos_int_continue --nostringval-- --nos
tringval-- 1 1 0 --nostringval-- %for_pos_int_continue 9 7
%oparray_pop --nostringval--
Dictionary stack:
--dict:1118/1686(ro)(G)-- --dict:0/20(G)-- --dict:75/200(L)--
--dict:75/200(L)-- --dict:105/127(ro)(G)-- --dict:247/347(ro)(G)--
--dict:21/24(L)--
Current allocation mode is local
Last OS error: 2
AFPL Ghostscript 8.50: Unrecoverable error, exit code 1
(gs version doesn't matter, HEAD contains the same bug.)
I could identify it as bug in pdf_main.ps:
% <pagedict> mark ... -proc- -
/namedactions 8 dict dup begin
/FirstPage {
/Page 1 3 -1 roll
} def
/LastPage {
counttomark 2 add index pdfpagecount /Page exch 3 -1 roll
} def
/NextPage {
counttomark 2 add index pdfpagenumber 1 add /Page exch 3 -1 roll
} def
/PrevPage {
counttomark 2 add index pdfpagenumber 1 sub /Page exch 3 -1 roll
} def
end readonly def
The "counttomark 2 add indx" get the dict for "pdfpagenumber".
However "pdfpagecount" doesn't use an argument, thus the dict
remains on the stack and will later break the "/LNK pdfmark",
because the pdfmark expects key value pairs and raises an error
messages if a lonely dict comes in between.
The syntax for /pdfpagecount and /pdfpagenumber (pdf_main.ps):
/pdfpagecount % - pdfpagecount <int>
/pdfpagenumber % <pagedict> pdfpagenumber <int>
Thus the fix is easy:
*** pdf_main.ps.org 2005-09-22 17:26:10.000000000 +0200
--- pdf_main.ps 2005-09-22 17:26:45.000000000 +0200
***************
*** 912,918 ****
/Page 1 3 -1 roll
} def
/LastPage {
! counttomark 2 add index pdfpagecount /Page exch 3 -1 roll
} def
/NextPage {
counttomark 2 add index pdfpagenumber 1 add /Page exch 3 -1 roll
--- 912,918 ----
/Page 1 3 -1 roll
} def
/LastPage {
! /Page pdfpagecount 3 -1 roll
} def
/NextPage {
counttomark 2 add index pdfpagenumber 1 add /Page exch 3 -1 roll
Yours sincerely
Heiko <oberdiek at uni-freiburg.de>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.pdf
Type: application/pdf
Size: 975 bytes
Desc: not available
Url : http://ghostscript.com/pipermail/gs-code-review/attachments/20050922/aaf73111/test.pdf
-------------- next part --------------
*** pdf_main.ps.org 2005-09-22 17:26:10.000000000 +0200
--- pdf_main.ps 2005-09-22 17:26:45.000000000 +0200
***************
*** 912,918 ****
/Page 1 3 -1 roll
} def
/LastPage {
! counttomark 2 add index pdfpagecount /Page exch 3 -1 roll
} def
/NextPage {
counttomark 2 add index pdfpagenumber 1 add /Page exch 3 -1 roll
--- 912,918 ----
/Page 1 3 -1 roll
} def
/LastPage {
! /Page pdfpagecount 3 -1 roll
} def
/NextPage {
counttomark 2 add index pdfpagenumber 1 add /Page exch 3 -1 roll
More information about the gs-code-review
mailing list