From f99879e05a77296a55075b3a684f399a52c400c4 Mon Sep 17 00:00:00 2001 From: Horst Rutter Date: Sun, 21 Mar 2021 00:58:11 +0100 Subject: [PATCH] Fix #311 --- pkg/api/test/booklet_test.go | 16 ++++++++++++++++ pkg/pdfcpu/read.go | 6 ++---- pkg/pdfcpu/write.go | 12 ++++++------ 3 files changed, 24 insertions(+), 10 deletions(-) diff --git a/pkg/api/test/booklet_test.go b/pkg/api/test/booklet_test.go index 97ac36a03..be99da3ae 100644 --- a/pkg/api/test/booklet_test.go +++ b/pkg/api/test/booklet_test.go @@ -1,3 +1,19 @@ +/* +Copyright 2021 The pdf Authors. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + package test import ( diff --git a/pkg/pdfcpu/read.go b/pkg/pdfcpu/read.go index 1d85ced04..a94fead2e 100644 --- a/pkg/pdfcpu/read.go +++ b/pkg/pdfcpu/read.go @@ -1275,10 +1275,8 @@ func readXRefTable(ctx *Context) (err error) { // Ensure valid freelist of objects. // Note: Acrobat 6.0 and later do not use the free list to recycle object numbers. - err = ctx.EnsureValidFreeList() - if err != nil { - return - } + // Not really necessary but call and fail silently so we at least get a chance to repair corrupt free lists. + ctx.EnsureValidFreeList() log.Read.Println("readXRefTable: end") diff --git a/pkg/pdfcpu/write.go b/pkg/pdfcpu/write.go index c1884ed03..18bd860e6 100644 --- a/pkg/pdfcpu/write.go +++ b/pkg/pdfcpu/write.go @@ -523,9 +523,9 @@ func sortedWritableKeys(ctx *Context) []int { // After inserting the last object write the cross reference table to disk. func writeXRefTable(ctx *Context) error { - if err := ctx.EnsureValidFreeList(); err != nil { - return err - } + //if err := ctx.EnsureValidFreeList(); err != nil { + // return err + //} keys := sortedWritableKeys(ctx) @@ -719,9 +719,9 @@ func writeXRefStream(ctx *Context) error { } // After the last insert of an object. - if err = xRefTable.EnsureValidFreeList(); err != nil { - return err - } + //if err = xRefTable.EnsureValidFreeList(); err != nil { + // return err + //} xRefStreamDict.Insert("Size", Integer(*xRefTable.Size))