@@ -19,6 +19,8 @@ package api
1919import (
2020 "io"
2121 "os"
22+ "path/filepath"
23+ "strconv"
2224 "time"
2325
2426 "github.com/pdfcpu/pdfcpu/pkg/log"
@@ -28,14 +30,14 @@ import (
2830)
2931
3032// appendTo appends inFile to ctxDest's page tree.
31- func appendTo (rs io.ReadSeeker , ctxDest * model.Context ) error {
33+ func appendTo (rs io.ReadSeeker , fName string , ctxDest * model.Context ) error {
3234 ctxSource , _ , _ , err := readAndValidate (rs , ctxDest .Configuration , time .Now ())
3335 if err != nil {
3436 return err
3537 }
3638
3739 // Merge source context into dest context.
38- return pdfcpu .MergeXRefTables (ctxSource , ctxDest )
40+ return pdfcpu .MergeXRefTables (fName , ctxSource , ctxDest )
3941}
4042
4143// MergeRaw merges a sequence of PDF streams and writes the result to w.
@@ -61,8 +63,8 @@ func MergeRaw(rsc []io.ReadSeeker, w io.Writer, conf *model.Configuration) error
6163
6264 ctxDest .EnsureVersionForWriting ()
6365
64- for _ , f := range rsc [1 :] {
65- if err = appendTo (f , ctxDest ); err != nil {
66+ for i , f := range rsc [1 :] {
67+ if err = appendTo (f , strconv . Itoa ( i ), ctxDest ); err != nil {
6668 return err
6769 }
6870 }
@@ -112,6 +114,12 @@ func Merge(destFile string, inFiles []string, w io.Writer, conf *model.Configura
112114 return err
113115 }
114116
117+ if conf .CreateBookmarks {
118+ if err := pdfcpu .EnsureOutlines (ctxDest , filepath .Base (destFile )); err != nil {
119+ return err
120+ }
121+ }
122+
115123 ctxDest .EnsureVersionForWriting ()
116124
117125 for _ , fName := range inFiles {
@@ -123,7 +131,7 @@ func Merge(destFile string, inFiles []string, w io.Writer, conf *model.Configura
123131 defer f .Close ()
124132
125133 log .CLI .Println (fName )
126- if err = appendTo (f , ctxDest ); err != nil {
134+ if err = appendTo (f , filepath . Base ( fName ), ctxDest ); err != nil {
127135 return err
128136 }
129137
@@ -138,12 +146,6 @@ func Merge(destFile string, inFiles []string, w io.Writer, conf *model.Configura
138146 return err
139147 }
140148
141- if conf .ValidationMode != model .ValidationNone {
142- if err := ValidateContext (ctxDest ); err != nil {
143- return err
144- }
145- }
146-
147149 return WriteContext (ctxDest , w )
148150}
149151
0 commit comments