From d8b14db198495d4879b5022b48a6b1ed513c0047 Mon Sep 17 00:00:00 2001 From: Phillip Darrall Date: Fri, 3 Oct 2025 09:50:44 +0100 Subject: [PATCH 1/3] Added ASCII85 decode support --- reader.go | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/reader.go b/reader.go index 48ad707..4acc633 100644 --- a/reader.go +++ b/reader.go @@ -4,17 +4,21 @@ import ( "bufio" "bytes" "compress/zlib" + "encoding/ascii85" "encoding/binary" "fmt" "io" "io/ioutil" "math" "os" + "regexp" "strconv" "github.com/pkg/errors" ) +var adobeASCII85 = regexp.MustCompile(`<~|~>`) + type PdfReader struct { availableBoxes []string stack []string @@ -1436,6 +1440,10 @@ func (this *PdfReader) rebuildContentStream(content *PdfValue) ([]byte, error) { // Set stream to uncompressed data stream = out.Bytes() + case "/ASCII85Decode": + if stream, err = uncompressASCII85(stream); err != nil { + return nil, err + } default: return nil, errors.New("Unspported filter: " + filters[i].Token) } @@ -1444,6 +1452,15 @@ func (this *PdfReader) rebuildContentStream(content *PdfValue) ([]byte, error) { return stream, nil } +func uncompressASCII85(compressed []byte) ([]byte, error) { + // compressed stream may contain <~ and ~> which are not standard ASCII85. Remove them before decoding + compressed = adobeASCII85.ReplaceAll(compressed, []byte{}) + var out bytes.Buffer + reader := ascii85.NewDecoder(bytes.NewBuffer(compressed)) + io.Copy(&out, reader) + return out.Bytes(), nil +} + func (this *PdfReader) getNumPages() (int, error) { if this.pageCount == 0 { return 0, errors.New("Page count is 0") From f2c110bf4797d950e3e8de6c10efcea0fbc1e9ff Mon Sep 17 00:00:00 2001 From: Phillip Darrall Date: Wed, 8 Apr 2026 09:46:55 +0100 Subject: [PATCH 2/3] Revert "Added ASCII85 decode support" This reverts commit d8b14db198495d4879b5022b48a6b1ed513c0047. --- reader.go | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/reader.go b/reader.go index 4acc633..48ad707 100644 --- a/reader.go +++ b/reader.go @@ -4,21 +4,17 @@ import ( "bufio" "bytes" "compress/zlib" - "encoding/ascii85" "encoding/binary" "fmt" "io" "io/ioutil" "math" "os" - "regexp" "strconv" "github.com/pkg/errors" ) -var adobeASCII85 = regexp.MustCompile(`<~|~>`) - type PdfReader struct { availableBoxes []string stack []string @@ -1440,10 +1436,6 @@ func (this *PdfReader) rebuildContentStream(content *PdfValue) ([]byte, error) { // Set stream to uncompressed data stream = out.Bytes() - case "/ASCII85Decode": - if stream, err = uncompressASCII85(stream); err != nil { - return nil, err - } default: return nil, errors.New("Unspported filter: " + filters[i].Token) } @@ -1452,15 +1444,6 @@ func (this *PdfReader) rebuildContentStream(content *PdfValue) ([]byte, error) { return stream, nil } -func uncompressASCII85(compressed []byte) ([]byte, error) { - // compressed stream may contain <~ and ~> which are not standard ASCII85. Remove them before decoding - compressed = adobeASCII85.ReplaceAll(compressed, []byte{}) - var out bytes.Buffer - reader := ascii85.NewDecoder(bytes.NewBuffer(compressed)) - io.Copy(&out, reader) - return out.Bytes(), nil -} - func (this *PdfReader) getNumPages() (int, error) { if this.pageCount == 0 { return 0, errors.New("Page count is 0") From 7d5856c50f561ce9f10c4c59633454ce723d6ab8 Mon Sep 17 00:00:00 2001 From: Phillip Darrall Date: Wed, 13 May 2026 13:15:10 +0100 Subject: [PATCH 3/3] Allow /Contents to be reference to array --- reader.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/reader.go b/reader.go index 90203f5..78f789a 100644 --- a/reader.go +++ b/reader.go @@ -1353,8 +1353,13 @@ func (this *PdfReader) getPageContent(objSpec *PdfValue) ([]*PdfValue, error) { if err != nil { return nil, errors.Wrap(err, "Failed to resolve object") } - contents = append(contents, content) - } else if objSpec.Type == PDF_TYPE_ARRAY { + if content.Value.Type == PDF_TYPE_ARRAY { + objSpec = content.Value + } else { + contents = append(contents, content) + } + } + if objSpec.Type == PDF_TYPE_ARRAY { // If objSpec is an array, loop through the array and recursively get page content and append to contents for i := 0; i < len(objSpec.Array); i++ { tmpContents, err := this.getPageContent(objSpec.Array[i])