prawnpdf / pdf-core

Implements low level PDF features for Prawn (experimental)
Other
23 stars 38 forks source link

Fix bug in Page#inherited_dictionary_value when in a #stamp_stream block #37

Closed ndbroadbent closed 12 months ago

ndbroadbent commented 5 years ago

#inherited_dictionary_value used the wrong dictionary when called from a #stamp_stream block. It uses @stamp_dictionary instead of the page @dictionary, so a call to page.dimensions would return nil.

I added a new #page_dictionary method that is called by #inherited_dictionary_value, which always returns the correct page dictionary.

This issue surfaced while using prawn-templates with prawn-blank (for adding AcroForm fields.)

ndbroadbent commented 5 years ago

I also merged in the changes from 0.8.1. (See #36)

pointlessone commented 4 years ago

@ndbroadbent could you please rebase your branch, add specs and a changelog entry?

ndbroadbent commented 4 years ago

Hi @pointlessone, thanks for taking a look! I have rebased and pushed the change. I will also try to find some time to add specs and a changelog entry and let you know once this is ready.

petergoldstein commented 2 years ago

@ndbroadbent I know it's been a while, but I was wondering you'd be able to submit a spec for this. I think if we had a spec we could shepherd it in. Thanks!

pointlessone commented 12 months ago

I didn't look too deep into it so I don't have too clear an understanding of this particular issue.

Stamps are implemented as form XObjects. They're separate from pages. They, too, contain a graphics stream but they do not participate in page dict property inheritance. There's not much overlap in Page and Form XObject dicts to even use inheritance. Stamps don't change after definition. Giving access to current page in the stamp definition might give a false impression that a stamp would adapt to page.

I'm not sure how to address this best but I don't think this is a good solution. At least from the API point of view.

If you must, you can catch page dimensions or other values of current page in local variables and use those in the stamp block. I believe, that should work and it doesn't look like stamp is more dynamic than it actually is.

ndbroadbent commented 6 months ago

Sorry for the delay on this issue! It's a tricky one and I'm not sure how to add a spec, but I'll try to add a minimal example to reproduce the issue that we are seeing. We are trying to update our code to use the latest version of pdf-core and prawn, and this is still an ongoing issue for us. One of the problems is that prawn calls page.dimensions[] in some places where dimensions returns nil. (But this issue is caused by prawn-templates when manipulating AcroForm fields.)

We would like to get back to using the released versions of gems on Rubygems, so I will attempt to add test cases and find a better solution for these issues. Thanks!