Skip to content

Commit 087a161

Browse files
wkirbyBurkhard Vogel-Kreykenbohm
authored andcommitted
Media box (#25)
* Handle case where MediaBox is a reference
1 parent 7109432 commit 087a161

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

1.17 KB
Binary file not shown.

lib/pdf/core/page.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,11 @@ def imported_page?
6161

6262
alias __dimensions dimensions if method_defined? :dimensions
6363
def dimensions
64-
return inherited_dictionary_value(:MediaBox) if imported_page?
64+
if imported_page?
65+
media_box = inherited_dictionary_value(:MediaBox)
66+
return media_box.data if media_box.is_a?(PDF::Core::Reference)
67+
return media_box
68+
end
6569

6670
coords = PDF::Core::PageGeometry::SIZES[size] || size
6771
[0, 0] +

spec/prawn/templates_spec.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,17 @@
238238
expect(hash[hash.trailer[:Info]].keys.include?(k)).to eq true
239239
end
240240
end
241+
242+
it 'returns correct dimensions when :MediaBox is a reference' do
243+
filename = "#{DATADIR}/pdfs/page_with_mediabox_reference.pdf"
244+
pdf = Prawn::Document.new(template: filename)
245+
246+
# expect the inherited value to be a reference
247+
expect(pdf.state.page.send(:inherited_dictionary_value, :MediaBox)).to be_a PDF::Core::Reference
248+
249+
# expect dimensions to come back as an array
250+
expect(pdf.state.page.dimensions).to be_a Array
251+
end
241252
end
242253

243254
describe 'Document#start_new_page with :template option' do

0 commit comments

Comments
 (0)