From d3cc23635112b72ad768c1e7dbc8c35be4e9a1a1 Mon Sep 17 00:00:00 2001 From: Samuel Melrose Date: Mon, 8 Oct 2018 10:27:39 +0000 Subject: [PATCH 1/2] Expose PDF Version #230 --- pdf/core/parser.go | 20 ++++++++++++++------ pdf/model/reader.go | 2 +- 2 files changed, 15 insertions(+), 7 deletions(-) mode change 100644 => 100755 pdf/core/parser.go mode change 100644 => 100755 pdf/model/reader.go diff --git a/pdf/core/parser.go b/pdf/core/parser.go old mode 100644 new mode 100755 index 6e03c932..0f76f7de --- a/pdf/core/parser.go +++ b/pdf/core/parser.go @@ -34,8 +34,7 @@ var reXrefEntry = regexp.MustCompile(`(\d+)\s+(\d+)\s+([nf])\s*$`) // PdfParser parses a PDF file and provides access to the object structure of the PDF. type PdfParser struct { - majorVersion int - minorVersion int + version Version rs io.ReadSeeker reader *bufio.Reader @@ -54,9 +53,18 @@ type PdfParser struct { streamLengthReferenceLookupInProgress map[int64]bool } +type Version struct { + Major int + Minor int +} + +func (v Version) String() string { + return fmt.Sprintf("%0d.%0d", v.Major, v.Minor) +} + // PdfVersion returns version of the PDF file. -func (parser *PdfParser) PdfVersion() string { - return fmt.Sprintf("%0d.%0d", parser.majorVersion, parser.minorVersion) +func (parser *PdfParser) PdfVersion() Version { + return parser.version } // GetCrypter returns the PdfCrypt instance which has information about the PDFs encryption. @@ -1539,8 +1547,8 @@ func NewParser(rs io.ReadSeeker) (*PdfParser, error) { common.Log.Error("Unable to parse version: %v", err) return nil, err } - parser.majorVersion = majorVersion - parser.minorVersion = minorVersion + parser.version.Major = majorVersion + parser.version.Minor = minorVersion parser.trailer = trailer diff --git a/pdf/model/reader.go b/pdf/model/reader.go old mode 100644 new mode 100755 index 5b38532f..bab18f2f --- a/pdf/model/reader.go +++ b/pdf/model/reader.go @@ -67,7 +67,7 @@ func NewPdfReader(rs io.ReadSeeker) (*PdfReader, error) { } // PdfVersion returns version of the PDF file. -func (this *PdfReader) PdfVersion() string { +func (this *PdfReader) PdfVersion() Version { return this.parser.PdfVersion() } From 7a641b09d278606f1bc713690bc8cb4f2a0f2444 Mon Sep 17 00:00:00 2001 From: Samuel Melrose Date: Tue, 9 Oct 2018 10:40:02 +0000 Subject: [PATCH 2/2] Add Comments for Expose PDF Version #230 --- pdf/core/parser.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pdf/core/parser.go b/pdf/core/parser.go index 0f76f7de..f98adc82 100755 --- a/pdf/core/parser.go +++ b/pdf/core/parser.go @@ -53,11 +53,13 @@ type PdfParser struct { streamLengthReferenceLookupInProgress map[int64]bool } +// Version holds the PDF version information for a file parsed by PdfParser type Version struct { Major int Minor int } +// String returns the PDF version as a string. Implements interface fmt.Stringer. func (v Version) String() string { return fmt.Sprintf("%0d.%0d", v.Major, v.Minor) }