App-DiffPDFText
view release on metacpan or search on metacpan
script/diff-pdf-text view on Meta::CPAN
unless (-f $filename) {
warn "diff-pdf-text: No such file or not a file: '$filename'\n";
$fail++;
return;
}
require App::PDFUtils;
my $res = App::PDFUtils::convert_pdf_to_text(
file => $filename,
fmt => $opt_fmt,
return_output_file => 1,
(defined $opt_pages ? (pages => $opt_pages) : ()),
);
my $file;
if ($res->[0] == 304) {
$file = $_[0];
} elsif ($res->[0] == 200) {
$file = $res->[2];
} else {
die "Can't convert PDF '$_[0]' to text: $res->[0] - $res->[1]";
}
push @CLI::MetaUtil::Getopt::Long::cli_argv, $file;
},
},
);
exit 1 if $fail;
require File::Which;
my $diff_cmd =
$ENV{DIFF_PDF_TEXT_DIFF_CMD} //
$ENV{DIFF_CMD} //
(File::Which::which("diffwc") ? "diffwc" : undef) // "diff";
require IPC::System::Options;
if ($opt_pager) {
IPC::System::Options::system({log=>1, shell=>1, env=>{COLOR=>1}}, $diff_cmd, "-ruN", @ARGV, \"|", 'less', '-R');
} else {
IPC::System::Options::system({log=>1}, $diff_cmd, "-ruN", @ARGV);
}
# ABSTRACT: Diff the text of two PDF documents
# PODNAME: diff-pdf-text
__END__
=pod
=encoding UTF-8
=head1 NAME
diff-pdf-text - Diff the text of two PDF documents
=head1 VERSION
This document describes version 0.006 of diff-pdf-text (from Perl distribution App-DiffPDFText), released on 2023-08-09.
=head1 SYNOPSIS
Use like you would use the Unix command B<diff>:
% diff-pdf-text [options] <FILE>...
=head1 DESCRIPTION
This is a wrapper for the Unix command B<diff>. It assumes that each input file
is a PDF file and tries to convert the file to text first using L<App::PDFUtils>
(which in turn uses B<pdftotext> CLI utility). It then passes the converted
text C<< diff -ruN >> command.
=head1 OPTIONS
These are options that are interpreted by B<diff-pdf-text> and not passed to
B<diff>.
B<Please specify these options before file names.>
=over
=item * --pdf-pages
Only diff a range of pages instead of the whole PDF. Example: 1,5-10,15.
Requires B<pdftk> to extract the page range.
=item * --(no-)pdf-fmt
Whether to apply `fmt` formatting to the `pdftotext` output. The default is yes;
use C<--no-pdf-fmt> to disable it.
=item * --pager
Run the output through pager. Currently this option uses C<less> and also forces
color output. The main use is to see colored diff with a pager.
=back
=head1 ENVIRONMENT
=head2 DEBUG
If set to true, do not cleanup temporary directories.
=head2 DIFF_CMD
String. Can be used to set path to diff command. See also
L</DIFF_PDF_TEXT_DIFF_CMD> which takes precedence.
=head2 DIFF_PDF_TEXT_DIFF_CMD
String. Can be used to set path to diff command. The defaultl is L<diffwc> if
available in PATH, or C<diff>. Takes precedence over L</DIFF_CMD>.
=head1 HOMEPAGE
Please visit the project's homepage at L<https://metacpan.org/release/App-DiffPDFText>.
=head1 SOURCE
Source repository is at L<https://github.com/perlancar/perl-App-DiffPDFText>.
=head1 SEE ALSO
Unix command L<diff>.
=head1 AUTHOR
perlancar <perlancar@cpan.org>
=head1 CONTRIBUTING
To contribute, you can send patches by email/via RT, or send pull requests on
GitHub.
Most of the time, you don't need to build the distribution yourself. You can
simply modify the code, then test via:
% prove -l
If you want to build the distribution (e.g. to try to install it locally on your
system), you can install L<Dist::Zilla>,
L<Dist::Zilla::PluginBundle::Author::PERLANCAR>,
L<Pod::Weaver::PluginBundle::Author::PERLANCAR>, and sometimes one or two other
Dist::Zilla- and/or Pod::Weaver plugins. Any additional steps required beyond
that are considered a bug and can be reported to me.
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2023, 2022 by perlancar <perlancar@cpan.org>.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=head1 BUGS
Please report any bugs or feature requests on the bugtracker website L<https://rt.cpan.org/Public/Dist/Display.html?Name=App-DiffPDFText>
When submitting a bug or request, please include a test-file or a
patch to an existing test-file that illustrates the bug or desired
feature.
=cut
( run in 1.389 second using v1.01-cache-2.11-cpan-64ef6c95b5d )