Skip to content

Instantly share code, notes, and snippets.

@jqr
Last active April 8, 2018 02:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save jqr/20e14b83c994b2378d76 to your computer and use it in GitHub Desktop.
Save jqr/20e14b83c994b2378d76 to your computer and use it in GitHub Desktop.

Ruby version test

This will create a document using DocRaptor with every major PrinceXML version supported and then inspect the output for metadata verifying the version used to produce the document.

git clone https://gist.github.com/20e14b83c994b2378d76.git docraptor-version-test
cd docraptor-version-test
bundle install
ruby version_test.rb
grep -a Producer *.pdf

With any luck, the output of the grep command should be:

version-10.pdf:<</Producer (Prince 10 rev 2 \(www.princexml.com\))>>
version-7.1.pdf:<</Producer (Prince 7.1 \(www.princexml.com\))>>
version-8.1.pdf:<</Producer (Prince 8.1 rev 5 \(www.princexml.com\))>>
version-9.0.pdf:<</Producer (Prince 9.0 rev 5 \(www.princexml.com\))>>
version-nil.pdf:<</Producer (Prince 10 rev 2 \(www.princexml.com\))>>

The version-nil.pdf may not match as it relies on your account's default PrinceXML version.

source "https://rubygems.org"
gem "doc_raptor"
GEM
remote: https://rubygems.org/
specs:
doc_raptor (0.5.0)
httparty (>= 0.7.0)
httparty (0.13.5)
json (~> 1.8)
multi_xml (>= 0.5.2)
json (1.8.3)
multi_xml (0.5.5)
PLATFORMS
ruby
DEPENDENCIES
doc_raptor
BUNDLED WITH
1.10.6
require "bundler"
Bundler.require
DocRaptor.api_key "YOUR_API_KEY_HERE"
puts "System information:"
puts " Ruby: #{RUBY_DESCRIPTION}"
puts " DocRaptor gem: #{DocRaptor::VERSION}"
VERSIONS = [nil, "7.1", "8.1", "9.0", "10"]
DOCRAPTOR_TEST_MODE = true
VERSIONS.each do |version|
docraptor_options = {
:test => DOCRAPTOR_TEST_MODE,
:strict => 'none',
:prince_options => {
:version => version
}
}
docraptor_options.delete(:prince_options) if version == nil
opts = docraptor_options.merge({:name =>'Test PDF generate', :document_content =>'<html><body>This is a pdf</body></html>'})
puts "Creating document..."
doc = DocRaptor.create(opts)
puts "#{doc.code} #{doc.message}"
abort unless doc.code == 200
filename = "version-#{version || "nil"}.pdf"
puts "Writing #{filename} ..."
File.open(filename, "w") do |f|
f.write(doc.body)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment