Bug 691075

Summary: Some pages are removed by pdfwrite when merging PDF files
Product: Ghostscript Reporter: Olivier DEPALLE <odepalle>
Component: PDF WriterAssignee: Ken Sharp <ken.sharp>
Status: RESOLVED DUPLICATE    
Severity: normal    
Priority: P4    
Version: 8.64   
Hardware: PC   
OS: Windows XP   
Customer: Word Size: ---

Description Olivier DEPALLE 2010-01-20 01:40:27 UTC
Some pages are removed by pdfwrite whene merging PDF files. The bookmarks 
order seems good but some of them don't link to the right pages.

Here is the GS command line:

gswin32c -dSAFER -dBATCH -dNOPAUSE -sDEVICE=pdfwrite -dCompatibilityLevel=1.3 -
sOutputFile=merged.pdf 1.PDF 4.PDF

GPL Ghostscript 8.64 (2009-02-03)
Copyright (C) 2009 Artifex Software, Inc.  All rights reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Processing pages 1 through 4.
Page 1
Page 2
Page 3
Page 4
Processing pages 1 through 68.
Page 1
Page 2
Page 3
Page 4
Page 5
Page 6
Page 7
Page 8
Page 9
Page 10
Page 11
Page 12
Page 13
Page 14
Page 15
Page 16
Page 17
Page 18
Page 19
Page 20
Page 21
Page 22
Page 23
Page 24
Page 25
Page 26
Page 27
Page 28
Page 29
Page 30
Page 31
Page 32
Page 33
Page 34
Page 35
Page 36
Page 37
Page 38
Page 39
Page 40
Page 41
Page 42
Page 43
Page 44
Page 45
Page 46
Page 47
Page 48
Page 49
Page 50
Page 51
Page 52
Page 53
Page 54
Page 55
Page 56
Page 57
Page 58
Page 59
Page 60
Page 61
Page 62
Page 63
Page 64
Page 65
Page 66
Page 67
Page 68
Comment 1 Ken Sharp 2010-01-20 01:56:20 UTC
You haven't supplied any example files to look at.

What do you mean when you say that 'pages are removed' ? Is the page count after
merging not the same as the total number of pages in each file (in your example,
72 pages)?

You appear in fact to be complaining that the bookmarks are not correct after
merging two files together. This is to be expected. Bookmarks are stored
separately to the page content and reference pages in the PDF file directly, if
you modify the page order (by inserting extra pages in front for example, as you
have here) then the page number references will no longer be correct.
Comment 2 Olivier DEPALLE 2010-01-20 02:02:06 UTC
The merged file is good, the bookmarks are not.
In fact, the bookmarks are bad:
- they are OK for the 4 first pages (first document)
- they are KO for the next pages (second document): the first bookmark links to
the first page of the merged file, not to the 5th...
Comment 3 Ken Sharp 2010-01-20 02:08:11 UTC
That's to be expected. The bookmarks in your second file reference pages 1 to
68, however those pages are now (in the merged file) at locations 5 to 72.

As a result the bookmarks are incorrect. Ghostscript and the pdfwrite device
don't actually have any way to know that you've merged two files together, all
the pdfwrite device knows is that its been given 72 pages to process, and a
bunch of pdfmark operations referencing those pages.

pdfwrite doesn't know that you have moved some of the pages, and so is unable to
correct the pdfmark references, thus the bookmarks are created pointing at
different pages.
Comment 4 Olivier DEPALLE 2010-01-20 02:39:36 UTC
Is there a way to recreate these bookmarks correctly before merging the files?
Comment 5 Hin-Tak Leung 2010-01-20 05:30:58 UTC
Ken's comment 3 is not entirely correct - this bug is actually the same as bug
688829 , for which an operational patch exists, but not accepted due to
stylistic reasons. I intend to go back to it one day. The reporter is free to
apply the patch himself.
Comment 6 Hin-Tak Leung 2010-01-20 05:32:30 UTC
The summary line is wrong - outline bookmarks are not relocated, that's all.
Same bug as 688829 .

*** This bug has been marked as a duplicate of 688829 ***