Skip to content

Commit

Permalink
Add GetObjectNums
Browse files Browse the repository at this point in the history
  • Loading branch information
Gunnsteinn Hall authored and Gunnsteinn Hall committed Aug 5, 2017
1 parent 22c2e5e commit 3261689
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions pdf/core/crossrefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type XrefObject struct {

// XrefTable is a map between object number and corresponding XrefObject.
// TODO (v3): Unexport.
// TODO: Consider changing to a slice, so can maintain the object order without sorting when analyzing.
type XrefTable map[int]XrefObject

// ObjectStream represents an object stream's information which can contain multiple indirect objects.
Expand Down
14 changes: 14 additions & 0 deletions pdf/core/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,20 @@ func (parser *PdfParser) Inspect() (map[string]int, error) {
return parser.inspect()
}

// GetObjectNums returns a sorted list of object numbers of the PDF objects in the file.
func (parser *PdfParser) GetObjectNums() []int {
objNums := []int{}
for _, x := range parser.xrefs {
objNums = append(objNums, x.objectNumber)
}

// Sort the object numbers to give consistent ordering of PDF objects in output.
// Needed since parser.xrefs is a map.
sort.Ints(objNums)

return objNums
}

func getUniDocVersion() string {
return common.Version
}
Expand Down
9 changes: 9 additions & 0 deletions pdf/model/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,15 @@ func (this *PdfReader) Inspect() (map[string]int, error) {
return this.parser.Inspect()
}

// GetObjectNums returns the object numbers of the PDF objects in the file
// Numbered objects are either indirect objects or stream objects.
// e.g. objNums := pdfReader.GetObjectNums()
// The underlying objects can then be accessed with
// pdfReader.GetIndirectObjectByNumber(objNums[0]) for the first available object.
func (r *PdfReader) GetObjectNums() []int {
return r.parser.GetObjectNums()
}

// Get specific object number.
func (this *PdfReader) GetIndirectObjectByNumber(number int) (PdfObject, error) {
obj, err := this.parser.LookupByNumber(number)
Expand Down

0 comments on commit 3261689

Please sign in to comment.