Merge pull request #233 from a1comms/v3-enhance-forms

Expose PDF Version #230
This commit is contained in:
Gunnsteinn Hall 2018-10-09 10:50:14 +00:00 committed by GitHub
commit 5f3f55ec8a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 7 deletions

22
pdf/core/parser.go Normal file → Executable file
View File

@ -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. // PdfParser parses a PDF file and provides access to the object structure of the PDF.
type PdfParser struct { type PdfParser struct {
majorVersion int version Version
minorVersion int
rs io.ReadSeeker rs io.ReadSeeker
reader *bufio.Reader reader *bufio.Reader
@ -54,9 +53,20 @@ type PdfParser struct {
streamLengthReferenceLookupInProgress map[int64]bool 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)
}
// PdfVersion returns version of the PDF file. // PdfVersion returns version of the PDF file.
func (parser *PdfParser) PdfVersion() string { func (parser *PdfParser) PdfVersion() Version {
return fmt.Sprintf("%0d.%0d", parser.majorVersion, parser.minorVersion) return parser.version
} }
// GetCrypter returns the PdfCrypt instance which has information about the PDFs encryption. // GetCrypter returns the PdfCrypt instance which has information about the PDFs encryption.
@ -1539,8 +1549,8 @@ func NewParser(rs io.ReadSeeker) (*PdfParser, error) {
common.Log.Error("Unable to parse version: %v", err) common.Log.Error("Unable to parse version: %v", err)
return nil, err return nil, err
} }
parser.majorVersion = majorVersion parser.version.Major = majorVersion
parser.minorVersion = minorVersion parser.version.Minor = minorVersion
parser.trailer = trailer parser.trailer = trailer

2
pdf/model/reader.go Normal file → Executable file
View File

@ -67,7 +67,7 @@ func NewPdfReader(rs io.ReadSeeker) (*PdfReader, error) {
} }
// PdfVersion returns version of the PDF file. // PdfVersion returns version of the PDF file.
func (this *PdfReader) PdfVersion() string { func (this *PdfReader) PdfVersion() Version {
return this.parser.PdfVersion() return this.parser.PdfVersion()
} }