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

Add support for PDF/A-1b #1029

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,3 @@ drop_to_console.rb
/bin
.DS_Store
*.pdf
/.byebug_history
4 changes: 2 additions & 2 deletions lib/prawn/document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class Document
:right_margin, :top_margin, :bottom_margin, :skip_page_creation,
:compress, :background, :info,
:text_formatter, :print_scaling,
:trailer, :enable_pdfa_1b
:enable_pdfa_1b
].freeze

# Any module added to this array will be included into instances of
Expand Down Expand Up @@ -384,7 +384,7 @@ def render(*a, &b)
# pdf.render_file "foo.pdf"
#
def render_file(filename)
File.open(filename, 'wb') { |f| render(f) }
File.open(filename, 'rb+') { |f| render(f) }
Copy link
Member

Choose a reason for hiding this comment

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

Why this change?

Copy link
Author

Choose a reason for hiding this comment

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

A file opened with 'wb' does not allow reading. My seek-solution reads the rendered body to avoid a second render pass. As you already pointed pointed out the flaw with seeking, I will revert this change.

Copy link
Author

Choose a reason for hiding this comment

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

Reverted.

end

# The bounds method returns the current bounding box you are currently in,
Expand Down
7 changes: 1 addition & 6 deletions manual/contents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,9 @@ def prawn_manual_document
old_default_external_encoding = Encoding.default_external
Encoding.default_external = Encoding::UTF_8

# We need to use a fixed trailer ID, otherwise the test for
# unintended manual changes will always trigger because of
# a random trailer ID.
trailer_id = PDF::Core::ByteString.new('PrawnPrawnPrawnP')
Prawn::ManualBuilder::Example.new(
skip_page_creation: true,
page_size: 'FOLIO',
trailer: { ID: [trailer_id, trailer_id] }
page_size: 'FOLIO'
) do
load_page '', 'cover'
load_page '', 'how_to_read_this_manual'
Expand Down
2 changes: 1 addition & 1 deletion spec/manual_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
MANUAL_HASH =
case RUBY_ENGINE
when 'ruby'
'c7202f015e36d02ac36dac38d88bb78a4dd439ec6d23268ebddaa15a8bcf7e790f203fd3e92d9c1b92c1a2806a03d7f5706c1550da29f281d25bb5540568445e'
'ac6e99bf22dd31c21c95295ae7b956a610ce98afcbae2e23df1648e0128b3be8728342d6d9622c73ff3702506e8b00d43557d19a77e7ebc313e8133155568efd'
when 'jruby'
'd2eb71ea3ddc35acb185de671a6fa48862ebad5727ce372e3a742f45d31447765c4004fbe5fbfdc1f5a32903ac87182c75e6abe021ab003c8af6e6cc33e0d01e'
end
Expand Down
9 changes: 1 addition & 8 deletions spec/prawn/document_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,14 +454,7 @@ def self.format(string)
end

it 'is idempotent' do
# We need to overwrite the trailer ID, otherwise each render
# pass will generate a new random ID and the documents would
# not match.
trailer_id = PDF::Core::ByteString.new(SecureRandom.random_bytes(16))
pdf = described_class.new(trailer: {
ID: [trailer_id, trailer_id]
})

pdf = described_class.new
contents = pdf.render
contents2 = pdf.render
expect(contents2).to eq(contents)
Expand Down