Project

pdf_spec

0.0
Low commit activity in last 3 years
No release in over a year
This library includes matchers that use Poppler and Cairo to render PDF files as images and compare them by the pixel
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

>= 0
~> 3.1

Runtime

> 2.3, < 6
 Project Readme

PdfSpec

PdfSpec includes rspec matchers to compare the appearance of PDF files. This is obviously most useful when you need to verify that you can produce a PDF that looks identical to a sample PDF file.

Installation

This library depends on the rmagick ruby gem.

Homebrew

brew install imagemagick
brew install ghostscript

MacPorts

sudo port install ImageMagick

Debian (Ubuntu)

The following was tested on Ubuntu 11.10, 12.04, and 20.04.

sudo apt-get install libmagickwand-dev

On Ubuntu 20.04 and later, you may run into the following error:

Magick::ImageMagickError:
   attempt to perform an operation not allowed by the security policy `PDF' @ error/constitute.c/IsCoderAuthorized/408

To resolve this, edit /etc/ImageMagick-6/policy.xml. Change <policy domain="coder" rights="none" pattern="PDF" /> to <policy domain="coder" rights="read|write" pattern="PDF" />. If that doesn't help, change <!-- <policy domain="module" rights="none" pattern="{PS,PDF,XPS}" /> --> to <policy domain="module" rights="read|write" pattern="{PS,PDF,XPS}" />.

(TODO) Gentoo

# Install libmagickwand

Use

To use the matchers in your tests, simple include the Matchers module into RSpec:

RSpec.configure do |config|
  config.include(PdfSpec::Matchers)
end

Or include it in certain tests:

describe "Testing PDFs" do
  include PdfSpec::Matchers

  it "should match..."; end
end

Matchers contains the have_same_pdf_appearance_as expectation which will render out PDF files to pixel buffers in memory and then compare them pixel by pixel.

it "should be the same PDF" do
  source_pdf = File.read("path/to/source")
  expected_pdf = File.read("path/to/expected")

  source.should have_same_pdf_appearance_as(expected_pdf)
end