Skip to content

Commit

Permalink
Add ability to get page sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
phpdave11 committed Jul 12, 2019
1 parent 1ad6332 commit bbb5385
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
10 changes: 10 additions & 0 deletions importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@ func (this *Importer) SetSourceFile(f string) {
}
}

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

if err != nil {
panic(err)
}

return result
}

func (this *Importer) ImportPage(pageno int, box string) int {
res, err := this.GetWriter().ImportPage(this.GetReader(), pageno, box)
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,22 @@ func (this *PdfReader) rebuildContentStream(content *PdfValue) ([]byte, error) {
return stream, nil
}

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

// Allocate result with the number of available boxes
result := make(map[int]map[string]map[string]float64, len(this.pages))

for i := 1; i <= len(this.pages); i++ {
result[i], err = this.getPageBoxes(i, k)
if result[i] == nil {
return nil, errors.Wrap(err, "Unable to get page box")
}
}

return result, nil
}

// Get all page box data
func (this *PdfReader) getPageBoxes(pageno int, k float64) (map[string]map[string]float64, error) {
var err error
Expand Down

0 comments on commit bbb5385

Please sign in to comment.