A gem to compare two PDFs and output the differences using diff-pdf.
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.
3.0, 3.1, 3.2, 3.3
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
Returns true if the PDFs match, false otherwise.
PdfMatcher.match?(pdf_a_data, pdf_b_data)
PdfMatcher.match?('/path/to/a.pdf', '/path/to/b.pdf')
PdfMatcher.match?(Pathname('/path/to/a.pdf'), Pathname('/path/to/b.pdf'))
If the PDFs do not match, a difference PDF file will be generated at the path specified.
PdfMatcher.match?(pdf_a_data, pdf_b_data, output_diff: '/path/to/diff.pdf')
The specified values will be set as options for the diff-pdf
command.
PdfMatcher.match?(pdf_a_data, pdf_b_data, diff_pdf_opts: ['--mark-differences', '--dpi=600'])
Returns the PDF match result as a PdfMatcher::MatchResult
object.
result = PdfMatcher.match(
pdf_a, pdf_b,
output_diff: nil,
diff_pdf_opts: nil
)
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 or the PDFs do not match.
result.diff_pdf_path #=> Pathname or nil
result.diff_pdf_data #=> "%PDF-..." or nil
PdfMatcher.config.diff_pdf_opts = %w(
--mark-differences
--channel-tolerance=40
)
See diff-pdf --help
for available options of the diff-pdf.
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.
$ bundle exec rake test
However, this gem requires diff-pdf. You can install it locally or use a docker container.
$ docker pull ghcr.io/hidakatsuya/ruby-with-diff-pdf:3.2
$ docker run -v $PWD:/src:cached -it ghcr.io/hidakatsuya/ruby-with-diff-pdf bash
> src# bundle install
> src# bundle exec rake test
Or, you can run tests instantlly like this:
$ docker run --rm -v $PWD:/src -it ghcr.io/hidakatsuya/ruby-with-diff-pdf bash -c "bundle install && bundle exec rake test"
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the PdfMatcher project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.