Project

pdfinfo

0.01
No commit activity in last 3 years
No release in over 3 years
Simple object oriented ruby wrapper around the pdfinfo command line utility
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.6
>= 0
~> 3.1.0
 Project Readme

Pdfinfo

Gem Version Build Status Coverage Status

Simple ruby wrapper around pdfinfo utility. This gem was written and tested around xpdf version 3.04.

Depdendecies

usage of this gem assumes that you have xpdf installed (which gives us access to the pdfinfo command). The fastest way to install xpdf:

$ brew install xpdf

Installation

Add this line to your application's Gemfile:

gem 'pdfinfo', '~> 1.4.2'

And then execute:

$ bundle

Or install it yourself as:

$ gem install pdfinfo

Usage

require 'pdfinfo'
pdfinfo = Pdfinfo.new('path/to/file.pdf')

pdfinfo.title         #=> "Title" # or nil
pdfinfo.subject       #=> "Subject" # or nil
pdfinfo.keywords      #=> ["Keyword1", "Keyword2"] # or nil
pdfinfo.author        #=> "Author Name" # or nil
pdfinfo.creator       #=> "Creator Name" # or nil
pdfinfo.producer      #=> "Producer Name" # or nil
pdfinfo.creation_date #=> 2014-10-26 20:50:45 -0700 # DateTime object
pdfinfo.modified_date #=> 2014-10-26 20:50:45 -0700 # DateTime object
pdfinfo.form          #=> "none" # (AcroForm / XFA / none)
pdfinfo.page_count    #=> 3
pdfinfo.width         #=> 612.0
pdfinfo.height        #=> 792.0
pdfinfo.size          #=> 1521 # file size in bytes
pdfinfo.pdf_version   #=> "1.3"
pdfinfo.encrypted?    #=> false # or true
pdfinfo.usage_rights  #=> {print: true, copy: true, change: true, add_notes: true} # always returns
pdfinfo.printable?    #=> true  # or false
pdfinfo.copyable?     #=> true  # or false
pdfinfo.changeable?   #=> true  # or false
pdfinfo.modifiable?   #=> true  # or false. alias for #changeable?
pdfinfo.annotatable?  #=> true  # or false
pdfinfo.tagged?       #=> false # or true
pdfinfo.optimized?    #=> false # or true

# Pages
pdfinfo.pages         #=> [#<Pdfinfo::Page height=792.0 width=612.0 rotation=0.0>, ...]
first_page = pdfinfo.page[0]
first_page.height     #=> 792.0
first_page.width      #=> 612.0
first_page.rotation   #=> 0.0

For encrypted files with a password you can pass in the user or owner password as options

pdfinfo = Pdfinfo.new("path/to/encrypted.pdf", user_password: 'foo')
# pdfinfo = Pdfinfo.new("path/to/encrypted.pdf", owner_password: 'foo')
pdfinfo.encrypted?    #=> true
pdfinfo.usage_rights  #=> {print: false, copy: false, change: false, add_notes: false}

You can directly set the location of the executable if its not located in your environment $PATH or you just want to point to a different location.

Pdfinfo.pdfinfo_command = '/another/bin/path/pdfinfo'
Pdfinfo.pdfinfo_command #=> '/another/bin/path/pdfinfo'

If you have an .xpdfrc file, you can set it globally or one-off with 'config_path'. With the pdfinfo command, Its main use will likely be to set text encoding and unicode mapping.

# set xpdfrc path globally
Pdfinfo.config_path = 'path/to/.xpdfrc'
# or one-off
Pdfinfo.new('path/to/file.pdf', config_path: 'path/to/.xpdfrc')

Recent Changes

see the CHANGELOG for recent changes

Running specs

generate pdf fixtures by first running

$ rake generate_fixtures

Then run specs by running

$ rake

TODO

  • add documentation for #to_hash
  • Error handling
  • type coersion is getting messy in initialize. refactor.