diff options
author | Ken Sharp <ken.sharp@artifex.com> | 2013-08-07 13:18:16 +0100 |
---|---|---|
committer | Ken Sharp <ken.sharp@artifex.com> | 2013-08-07 13:18:16 +0100 |
commit | 073f460af5bb37edb1849c5d6235048598100437 (patch) | |
tree | 021ac56532fd349fa010ee6aa4e1f0d3bd8d4038 | |
parent | 22e66c90bf173e4787717137a25833b4aa823993 (diff) | |
download | ghostpdl-073f460af5bb37edb1849c5d6235048598100437.tar.gz |
PDF interpreter - improve handling of pdfmarks when we have multiple input files
Bug #688542 "Bookmarks Get Lost In PDF"
Bug #688829 "Merging PDF files using gs: outlines and links not updated"
The pdfmarks generated by the PDF interpreter for Outlines and Links use the
page number relative to the start of the current input file. For single
input files this works fine, but when we have multiple input files, we end
up with outlines and links pointing to the wrong place.
To resolve this we need to know, at the start of any PDF file, how many pages
have already been processed, and then we will add this value to the nominal
page number when creating the pdfmarks.
Hin-Tak provided a solution (#688829) that used globaldict, which Alex rejected
for that reason. This commit executes currentpagedevice at the start of every
PDF input file, and stores in in /CumulativePageCount. We can then use this
to generate pdfmarks which are correct.
Even if PDF and PostScript input files are mingled, the PDF-generated pdfmarks
will still be correct.
We won't make any attempt to correct PostScript input, if you are creating a
PostScript program, you should get it right. If you really must merge, then
use pdfwrite to create the individual PDF files, and then merge those.
It is possible that other types of generated pdfmark will need similar
alteration, we'll tackle those as they turn up.
-rw-r--r-- | gs/Resource/Init/pdf_main.ps | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/gs/Resource/Init/pdf_main.ps b/gs/Resource/Init/pdf_main.ps index a81fecb03..a59b7a3ec 100644 --- a/gs/Resource/Init/pdf_main.ps +++ b/gs/Resource/Init/pdf_main.ps @@ -188,6 +188,7 @@ currentdict /runpdfstring .undef GS_PDF_ProcSet begin pdfdict begin pdfopen begin + /CumulativePageCount currentpagedevice /PageCount get def } bind def /runpdfpagerange { % - runpdfpagerange <firstpage#> <lastpage#> @@ -1501,7 +1502,7 @@ end readonly def pop % the "false" flag dup pdf_cached_PDF2PS_matrix exch dup /Rotate pget not { 0 } if 90 idiv exch - pdfpagenumber + pdfpagenumber CumulativePageCount add //true % now we have a page# and a transformation matrix } if } if @@ -1516,6 +1517,7 @@ end readonly def 3 -1 roll } { dup type /integertype eq { + CumulativePageCount add /Page exch 1 add 4 2 roll } { pop @@ -1529,10 +1531,10 @@ end readonly def } bind def % <pagedict> mark ... -proc- <page#> <error> /namedactions 8 dict dup begin - /FirstPage { 1 //false } def - /LastPage { pdfpagecount //false } def - /NextPage { counttomark 2 add index pdfpagenumber 1 add dup pdfpagecount gt } bind def - /PrevPage { counttomark 2 add index pdfpagenumber 1 sub dup 1 lt } bind def + /FirstPage { 1 /CumulativePageCount get add //false } def + /LastPage { pdfpagecount /CumulativePageCount get add //false } def + /NextPage { counttomark 2 add index pdfpagenumber 1 add dup pdfpagecount gt exch /CumulativePageCount get add exch} bind def + /PrevPage { counttomark 2 add index pdfpagenumber 1 sub dup 1 lt exch /CumulativePageCount get add exch} bind def end readonly def % <pagedict> <annotdict> -proc- - /annottypes 5 dict dup begin |