0.0
The project is in a healthy, maintained state
PdfMatcher is a gem to compare two PDFs and output the differences using diff-pdf
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
 Project Readme

PdfMatcher

Gem Version Test

A gem to compare two PDFs and output the differences using diff-pdf.

Prerequisites

diff-pdf Required

This gem requires diff-pdf. See the README.md for how to install it.

Note that you can install it with hidakatsuya/setup-diff-pdf in GitHub Action.

Supported Ruby Versions

2.6, 2.7, 3.0

Installation

Add this line to your application's Gemfile:

gem 'pdf_matcher'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install pdf_matcher

Usage

require 'pdf_matcher'

PdfMatcher.match?(pdf_a, pdf_b) #=> boolean

PdfMatcher.match?('/path/to/a.pdf', '/path/to/b.pdf') #=> boolean
PdfMatcher.match?(Pathname('/path/to/a.pdf'), Pathname('/path/to/b.pdf')) #=> boolean

PdfMatcher.match?(pdf_a, pdf_b, output_diff: '/path/to/diff.pdf') #=> boolean
PdfMatcher.match?(pdf_a, pdf_b, diff_pdf_opts: ['--dpi=300']) #=> boolean

result = PdfMatcher.match(
  pdf_a, pdf_b,
  output_diff: nil,  # or '/path/to/diff.pdf' or Pathname('/path/to/diff.pdf')
  diff_pdf_opts: nil # or ['--dpi=300']
)
result.matched? #=> boolean

# Returns nil if pdf data is passed, otherwise returns path as Pathname.
result.pdf1_path #=> Pathname or nil
result.pdf2_path #=> Pathname or nil

result.pdf1_data #=> "%PDF-..."
result.pdf2_data #=> "%PDF-..."

# Returns nil if the output_diff parameter is nil.
result.diff_pdf_path #=> Pathname or nil
result.diff_pdf_data #=> "%PDF-..." or nil

PdfMatcher.config.diff_pdf_opts = ['--dpi=300']

Use in Testing Frameworks

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/hidakatsuya/pdf_matcher. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

Testing

$ bundle exec rake test

However, this gem requires diff-pdf. You can install it locally or use a docker container.

$ docker build -t pdf_matcher:latest .
$ docker run -v $PWD:/src:cached -it pdf_matcher bash

> src# bundle install
> src# bundle exec rake test

Or, you can run tests instantlly like this:

$ docker run --rm -v $PWD:/src -it pdf_matcher bash -c "bundle install && bundle exec rake test"

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the PdfMatcher project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.