Preflight

Check your PDF files meet the standard you require.

The full PDF spec is a beast, and there are any number of ways of producing a valid PDF. Receivers of PDF files may need to ensure the files they’re sent meet a particular set of requirements, be it PDF/X, PDF/A or just “images must be 300 dpi or greater”. These checks are called preflight.

There’s expensive software around that can preflight for you, but it’s often difficult to script and you know, expensive.

This may not check as comprehensively as the official preflight tools from Adobe and friends, but hopefully it’ll get you most of the way with less stress.

Installation

gem install preflight

Usage

Standard Profile ( PDF/X-1a )

To test a PDF file against a well known standard and rule set.

require "preflight"

preflight = Preflight::Profiles::PDFX1A.new

puts preflight.check("somefile.pdf").inspect

File.open("somefile.pdf", "rb") do |file|
  puts preflight.check(file).inspect
end

Custom Profile

Create a custom set of rules to check against.

require "preflight"

class MyPreflight
  include Preflight::Profile

  profile_name "simple-pdf"

  rule Preflight::Rules::MaxVersion, 1.4
  rule Preflight::Rules::NoEncryption
  rule Preflight::Rules::DocumentId
end

preflight = MyPreflight.new

puts preflight.check("somefile.pdf").inspect

Extend A Profile

Use an existing rule set as the base for a larger set of rules.

require "preflight"

class MyPreflight
  include Preflight::Profile

  profile_name "simple-pdf"

  import Preflight::Profiles::PDFX1A

  rule Preflight::Rules::MaxVersion, 1.4
  rule Preflight::Rules::NoEncryption
  rule Preflight::Rules::DocumentId
end

preflight = MyPreflight.new

puts preflight.check("somefile.pdf").inspect

Adding Rules to a Profile Instance

Use an existing rule set as the base for a larger set of rules by adding rules to a profile instance. Useful when the required set of rules depends dynamic conditions.

require "preflight"

preflight = Preflight::Profiles::PDFX1A.new
prefight.rule Preflight::Rules::MaxVersion, 1.4

puts preflight.check("somefile.pdf").inspect

Status

This library is in an early stage of development. Use at your own risk.

Compatibility

This is pure ruby should run on most ruby VMs. I develop on MRI 1.9.2.

Further Reading