NAME App::PDFUtils - Command-line utilities related to PDF files VERSION This document describes version 0.016 of App::PDFUtils (from Perl distribution App-PDFUtils), released on 2024-09-28. SYNOPSIS DESCRIPTION This distribution provides tha following command-line utilities related to PDF files: 1. add-pdf-password 2. compress-pdf 3. grep-from-pdf 4. less-pdf-text 5. pdf-has-password 6. pdfgrep 7. pdfnopass 8. remove-pdf-password FUNCTIONS add_pdf_password Usage: add_pdf_password(%args) -> [$status_code, $reason, $payload, \%result_meta] Password-protect PDF files. This program is a wrapper for qpdf to password-protect PDF files (in-place). This is the counterpart for remove-pdf-password. Why use this wrapper instead of qpdf directly? This wrapper offers configuration file support, where you can put the password(s) you want to use there. The wrapper also offers multiple file support and additional options, e.g. whether to create backup. This function is not exported. Arguments ('*' denotes required arguments): * backup => *bool* (default: 1) Whether to backup the original file to ORIG~. * files* => *array[filename]* (No description) * password* => *str* (No description) Returns an enveloped result (an array). First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata. Return value: (any) compress_pdf Usage: compress_pdf(%args) -> [$status_code, $reason, $payload, \%result_meta] Make PDF smaller. This utility is a wrapper for gs (GhostScript) and is equivalent to the following command: % gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=output.pdf input.pdf This wrapper offers support for multiple files and automatically naming output "INPUT.compressed.pdf" by default. This function is not exported. Arguments ('*' denotes required arguments): * files* => *array[filename]* (No description) * overwrite => *bool* (No description) * setting => *str* (default: "ebook") (No description) Returns an enveloped result (an array). First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata. Return value: (any) convert_pdf_to_text Usage: convert_pdf_to_text(%args) -> [$status_code, $reason, $payload, \%result_meta] Convert PDF file to text. This utility uses one of the following backends: * pdftotext as well as optionally uses pdftk to manipulate PDF, and fmt to format text. It offers some options and conveniences like page ranges, output file specification, whether to overwrite existing files, etc. TODO: add ocrmypdf as backend. This function is not exported. Arguments ('*' denotes required arguments): * file* => *filename* Input file. * fmt => *bool* Run Unix fmt over the txt output. * output => *filename* Output path. * overwrite => *bool* (No description) * pages => *uint_range* Only convert a range of pages. * raw => *bool* If set to true, will run pdftotext with -raw option. * return_output_file => *bool* Return the path of output file instead. This is useful when you do not specify an output file but do not want to show the converted document to stdout, but instead want to get the path to a temporary output file. Returns an enveloped result (an array). First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata. Return value: (any) pdf_has_password Usage: pdf_has_password(%args) -> [$status_code, $reason, $payload, \%result_meta] Check if PDF file has password. This is a wrapper for "qpdf --check". The wrapper offers additional options like `--quiet``. This function is not exported. Arguments ('*' denotes required arguments): * file* => *filename* Input file. * quiet => *bool* (No description) Returns an enveloped result (an array). First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata. Return value: (any) remove_pdf_password Usage: remove_pdf_password(%args) -> [$status_code, $reason, $payload, \%result_meta] Remove password from PDF files. This program is a wrapper for qpdf to remove passwords from PDF files (in-place). The motivation for this wrapper is the increasing occurence of financial institutions sending financial statements or documents in the format of password-protected PDF file. This is annoying when we want to archive the file or use it in an organization because we have to remember different passwords for different financial institutions and re-enter the password everytime we want to use the file. (The banks could've sent the PDF in a password-protected .zip, or use PGP-encrypted email, but I digress.) Compared to using qpdf directly, this wrapper offers some additional features/options and convenience, for example: multiple file support, multiple password matching attempt, configuration file, option whether you want backup, etc. You can provide the passwords to be tried in a configuration file, "~/remove-pdf-password.conf", e.g.: passwords = pass1 passwords = pass2 passwords = pass3 or: passwords = ["pass1", "pass2", "pass3"] This function is not exported. Arguments ('*' denotes required arguments): * backup => *bool* (default: 1) Whether to backup the original file to ORIG~. * files* => *array[filename]* (No description) * passwords => *array[str]* (No description) Returns an enveloped result (an array). First element ($status_code) is an integer containing HTTP-like status code (200 means OK, 4xx caller error, 5xx function error). Second element ($reason) is a string containing error message, or something like "OK" if status is 200. Third element ($payload) is the actual result, but usually not present when enveloped result is an error response ($status_code is not 2xx). Fourth element (%result_meta) is called result metadata and is optional, a hash that contains extra information, much like how HTTP response headers provide additional metadata. Return value: (any) HOMEPAGE Please visit the project's homepage at . SOURCE Source repository is at . SEE ALSO diff-pdf-text from App::DiffPDFText. AUTHOR perlancar 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 Dist::Zilla, Dist::Zilla::PluginBundle::Author::PERLANCAR, 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. COPYRIGHT AND LICENSE This software is copyright (c) 2024, 2023, 2022, 2021, 2020, 2017 by perlancar . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. BUGS Please report any bugs or feature requests on the bugtracker website 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.