Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix page resources not being loaded from parent nodes #78

Merged
merged 1 commit into from
Jun 7, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions model/page.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func (p *PdfPage) Duplicate() *PdfPage {
// Note that a new container is created (indirect object).
func (r *PdfReader) newPdfPageFromDict(p *core.PdfObjectDictionary) (*PdfPage, error) {
page := NewPdfPage()
page.pageDict = p // TODO
page.pageDict = p

d := *p

Expand Down Expand Up @@ -138,8 +138,8 @@ func (r *PdfReader) newPdfPageFromDict(p *core.PdfObjectDictionary) (*PdfPage, e
}
} else {
// If Resources not explicitly defined, look up the tree (Parent objects) using
// the getResources() function. Resources should always be accessible.
resources, err := page.getResources()
// the getParentResources() function. Resources should always be accessible.
resources, err := page.getParentResources()
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -405,12 +405,8 @@ func (p *PdfPage) GetMediaBox() (*PdfRectangle, error) {
return nil, errors.New("media box not defined")
}

// Get the inheritable resources, either from the page or or a higher up page/pages struct.
func (p *PdfPage) getResources() (*PdfPageResources, error) {
if p.Resources != nil {
return p.Resources, nil
}

// getParentResources searches for page resources in the parent nodes of the page.
func (p *PdfPage) getParentResources() (*PdfPageResources, error) {
node := p.Parent
for node != nil {
dict, ok := core.GetDict(node)
Expand Down