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 case where prawn-templates would cause PDF contents to disappear #21

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

ndbroadbent
Copy link
Contributor

I ran into an issue with a PDF, where prawn-templates would cause the original PDF contents to disappear after adding it's own content stream.

I figured out the reason for this - :Contents was a reference that pointed to an array of references, which is a case that prawn-templates didn't appear to handle. I've annotated a screenshot from the pdfwalker tool:

screen shot 2017-10-18 at 8 43 00 pm

This PR just adds support for this case, which fixes the issue.

@hasmanyguitars
Copy link

@ndbroadbent Thanks for this fix! Have you seen any new issues arise from using this patch?

@ndbroadbent
Copy link
Contributor Author

Hi @hasmanyguitars, I've been using this patch for the last few months and haven't seen any problems. It seems to work fine, but there might be a better fix, or a better way to refactor the code. I'm not too familiar with prawn-templates

@gettalong
Copy link
Member

According to the PDF spec the /Contents key may either be a reference to a content stream or an array of references to content streams. The fix makes sure that no nested arrays are created. And there should not be any new Prawn issues due to this fix since Prawn is already aware that /Contents may be an array.

@content = document.ref({})
dictionary.data[:Contents] << document.state.store[@content]
contents = ensure_contents_array
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to split this in two distinct operations? ensure_contents_array looks a lot like a command and return value here appears to be circumstantial.

@bvogel
Copy link

bvogel commented Nov 9, 2021

This issue is VERY OLD. Is it still relevant after the latest releases?

@gettalong
Copy link
Member

@bvogel As far as I can tell, yes, since the fix is not yet incorporated.

@petergoldstein
Copy link
Contributor

@ndbroadbent I know it's been a while. Any chance you have a sample PDF around which I can build a test?

@ndbroadbent
Copy link
Contributor Author

@petergoldstein Sorry for the delay! I'll try to create a sample PDF and add a test case that demonstrates the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

7 participants