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
Open
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
17 changes: 13 additions & 4 deletions lib/pdf/core/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,27 @@ def initialize(document, options = {})
end
end

# If :Contents is a reference to an array, returns the resolved reference.
# Otherwise, makes sure :Contents is an array.
def ensure_contents_array
contents = dictionary.data[:Contents]
if contents.is_a?(PDF::Core::Reference) && contents.data.is_a?(Array)
return contents.data
end
# Ensure contents is an array.
dictionary.data[:Contents] = Array(contents)
end

# As per the PDF spec, each page can have multiple content streams. This
# will add a fresh, empty content stream this the page, mainly for use in
# loading template files.
#
def new_content_stream
return if in_stamp_stream?

unless dictionary.data[:Contents].is_a?(Array)
dictionary.data[:Contents] = [content]
end
@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.

contents << document.state.store[@content]
document.open_graphics_state
end

Expand Down