Skip to content

Commit

Permalink
Add document ID to trailer for PDF-X spec compat
Browse files Browse the repository at this point in the history
  • Loading branch information
bousquet committed May 26, 2015
1 parent 997b8a6 commit e083cb9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/pdf/core/document_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def initialize(options)
@version = 1.3
@pages = []
@page = nil
@trailer = {}
@trailer = options.fetch(:trailer, default_trailer)
@compress = options.fetch(:compress, false)
@encrypt = options.fetch(:encrypt, false)
@encryption_key = options[:encryption_key]
Expand Down Expand Up @@ -71,6 +71,14 @@ def render_body(output)
ref.object)
end
end

private

# Document ID is required by PDF-X spec, presence ok for standard PDF
def default_trailer
{ :ID => 2.times.map { SecureRandom.hex(8) }}
end

end
end
end
23 changes: 23 additions & 0 deletions spec/document_state_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require_relative "spec_helper"

describe "PDF Document State" do
before { @state = PDF::Core::DocumentState.new({}) }

describe "initialization" do
it { expect(@state.compress).to eq(false) }
it { expect(@state.encrypt).to eq(false) }
it { expect(@state.skip_encoding).to eq(false) }
end

describe "normalize_metadata" do
it { expect(@state.store.info.data[:Creator]).to eq("Prawn") }
it { expect(@state.store.info.data[:Producer]).to eq("Prawn") }
end

describe "default trailer" do
it "should contain an ID entry with two values in trailer" do
expect(@state.trailer[:ID].count).to eq(2)
end
end

end

0 comments on commit e083cb9

Please sign in to comment.