Skip to content

Commit d568466

Browse files
committed
Fix #844
1 parent deb697d commit d568466

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

pkg/api/api.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,20 @@ func ReadAndValidate(rs io.ReadSeeker, conf *model.Configuration) (ctx *model.Co
155155
return ctx, nil
156156
}
157157

158-
// ReadValidateAndOptimize returns an optimized model.Context of rs ready for processing.
158+
// ReadValidateAndOptimize returns an optimized model.Context of rs ready for processing a specific command.
159+
// conf.Cmd is expected to be configured properly.
159160
func ReadValidateAndOptimize(rs io.ReadSeeker, conf *model.Configuration) (ctx *model.Context, err error) {
161+
if conf == nil {
162+
return nil, errors.New("pdfcpu: ReadValidateAndOptimize: missing conf")
163+
}
164+
160165
ctx, err = ReadAndValidate(rs, conf)
161166
if err != nil {
162167
return nil, err
163168
}
164169

170+
// With the exception of the OPTIMIZE command optimization of the cross reference table is optional but usually recommended.
171+
// For large or complex files it may make sense to skip optimization.
165172
if conf.Cmd == model.OPTIMIZE || conf.Optimize {
166173
if err = OptimizeContext(ctx); err != nil {
167174
return nil, err
@@ -197,7 +204,6 @@ func Write(ctx *model.Context, w io.Writer, conf *model.Configuration) error {
197204
}
198205

199206
func WriteIncr(ctx *model.Context, rws io.ReadWriteSeeker, conf *model.Configuration) error {
200-
201207
if log.StatsEnabled() {
202208
log.Stats.Printf("XRefTable:\n%s\n", ctx)
203209
}

pkg/api/extract.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,8 @@ func ExtractPages(rs io.ReadSeeker, outDir, fileName string, selectedPages []str
218218

219219
if conf == nil {
220220
conf = model.NewDefaultConfiguration()
221-
conf.Cmd = model.EXTRACTPAGES
222221
}
222+
conf.Cmd = model.EXTRACTPAGES
223223

224224
ctx, err := ReadValidateAndOptimize(rs, conf)
225225
if err != nil {

0 commit comments

Comments
 (0)