Skip to content

Commit

Permalink
Fix case where prawn-templates would cause PDF contents to disappear
Browse files Browse the repository at this point in the history
  • Loading branch information
ndbroadbent committed Oct 18, 2017
1 parent ec2d24d commit cb47931
Showing 1 changed file with 13 additions and 4 deletions.
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
contents << document.state.store[@content]
document.open_graphics_state
end

Expand Down

0 comments on commit cb47931

Please sign in to comment.