Skip to content

Commit

Permalink
Merge pull request #16 from bousquet/doc_id
Browse files Browse the repository at this point in the history
Add document ID to trailer for PDF/X
  • Loading branch information
packetmonkey committed May 30, 2015
2 parents 997b8a6 + 2fe6652 commit 6b1b646
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/pdf/core/document_state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ def initialize(options)
normalize_metadata(options)

if options[:print_scaling]
@store = PDF::Core::ObjectStore.new(:info => options[:info],
@store = PDF::Core::ObjectStore.new(:info => options[:info],
:print_scaling => options[:print_scaling])
else
@store = PDF::Core::ObjectStore.new(:info => options[:info])
Expand All @@ -14,7 +14,7 @@ def initialize(options)
@version = 1.3
@pages = []
@page = nil
@trailer = {}
@trailer = options.fetch(:trailer, {})
@compress = options.fetch(:compress, false)
@encrypt = options.fetch(:encrypt, false)
@encryption_key = options[:encryption_key]
Expand Down Expand Up @@ -71,6 +71,7 @@ def render_body(output)
ref.object)
end
end

end
end
end
30 changes: 30 additions & 0 deletions spec/document_state_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
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) }
it { expect(@state.trailer).to eq({}) }
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 "given a trailer ID with two values" do
before do
@state = PDF::Core::DocumentState.new({
trailer: { :ID => ["myDoc","versionA"] }
})
end

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

end

0 comments on commit 6b1b646

Please sign in to comment.