mirror of
https://github.com/unidoc/unipdf.git
synced 2025-04-30 13:48:51 +08:00
Merge pull request #233 from a1comms/v3-enhance-forms
Expose PDF Version #230
This commit is contained in:
commit
5f3f55ec8a
22
pdf/core/parser.go
Normal file → Executable file
22
pdf/core/parser.go
Normal file → Executable 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.
|
||||
type PdfParser struct {
|
||||
majorVersion int
|
||||
minorVersion int
|
||||
version Version
|
||||
|
||||
rs io.ReadSeeker
|
||||
reader *bufio.Reader
|
||||
@ -54,9 +53,20 @@ 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)
|
||||
}
|
||||
|
||||
// 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 +1549,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
|
||||
|
||||
|
2
pdf/model/reader.go
Normal file → Executable file
2
pdf/model/reader.go
Normal file → Executable file
@ -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()
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user