Skip to content

Commit

Permalink
Add function to get number of pages
Browse files Browse the repository at this point in the history
  • Loading branch information
phpdave11 committed May 17, 2020
1 parent 8c54615 commit 301f4f3
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,16 @@ func (this *Importer) SetSourceStream(rs *io.ReadSeeker) {
}
}

func (this *Importer) GetNumPages() int {
result, err := this.GetReader().getNumPages()

if err != nil {
panic(err)
}

return result
}

func (this *Importer) GetPageSizes() map[int]map[string]map[string]float64 {
result, err := this.GetReader().getAllPageBoxes(1.0)

Expand Down
10 changes: 10 additions & 0 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type PdfReader struct {
sourceFile string
curPage int
alreadyRead bool
pageCount int
}

func NewPdfReaderFromStream(rs io.ReadSeeker) (*PdfReader, error) {
Expand Down Expand Up @@ -1238,6 +1239,7 @@ func (this *PdfReader) readPages() error {
if err != nil {
return errors.Wrap(err, "Failed to get page count")
}
this.pageCount = pageCount.Int

// Allocate pages
this.pages = make([]*PdfValue, pageCount.Int)
Expand Down Expand Up @@ -1432,6 +1434,14 @@ func (this *PdfReader) rebuildContentStream(content *PdfValue) ([]byte, error) {
return stream, nil
}

func (this *PdfReader) getNumPages() (int, error) {
if this.pageCount == 0 {
return 0, errors.New("Page count is 0")
}

return this.pageCount, nil
}

func (this *PdfReader) getAllPageBoxes(k float64) (map[int]map[string]map[string]float64, error) {
var err error

Expand Down

0 comments on commit 301f4f3

Please sign in to comment.