signer is an R package that lets you digitally sign PDF documents and verify digital signatures in PDFs. It uses external tools like BatchPDFSignPortable.jar for signing and pdfsig (part of the Poppler library) for verifying signatures.
Installation
You can install the package directly from GitHub:
# Install the package directly from GitHub
devtools::install_github("StrategicProjects/signer")Features
This package provides two main functionalities:
1. sign_pdf()
The sign_pdf() function allows you to digitally sign a PDF document using the BatchPDFSignPortable.jar file. The signature can include custom text, and you can control the positioning of the signature in the document.
Usage Example:
sign_pdf(
pdf_file = "input.pdf",
output_file = "signed_output.pdf",
keystore_path = "keystore.p12",
keystore_password = "password",
signtext = "Document digitally signed by CastLab",
validate_link = "http://castlab.org/validate",
translate = TRUE
)Parameters:
-
pdf_file: Path to the input PDF file. -
output_file: Path where the signed PDF will be saved. -
fs,rh,rw,rx,ry: Font size, height, width, and signature coordinates. -
page: Page number where the signature will be placed. -
signtext: Custom text to include in the signature. -
validate_link: Optional link for validating the signed document. -
keystore_path: Path to the.p12file containing the key and certificate. -
keystore_password: Password for the.p12file. -
translate: IfTRUE, the signature text will be in Portuguese; otherwise, it will be in English (default).
2. verify_pdf_signature()
The verify_pdf_signature() function checks the digital signatures in a PDF using the pdfsig command. You can also choose to translate the output to Portuguese.
Usage Example:
result <- verify_pdf_signature("signed_document.pdf", translate = TRUE)
print(result)Dependencies
This package is supported only on Linux and macOS. It requires the following external tools:
-
Java: Required to run
BatchPDFSignPortable.jarfor signing PDFs. -
Poppler: To verify signatures using
pdfsig, Poppler must be installed on the system.pdfsigis part of the Poppler library (https://poppler.freedesktop.org/).
Generating a Certificate using Command Line
You can also generate a digital certificate from the command line using OpenSSL. Here are the steps:
Credits
This package uses two external tools for signing and verifying PDF documents:
-
BatchPDFSignPortable.jar: Developed by Josep Marxuach (https://github.com/jmarxuach/BatchPDFSign),
BatchPDFSignis a Java utility for signing PDF documents. -
pdfsig: Part of the Poppler library,
pdfsigis a command-line tool used to verify signatures in PDF documents. The Poppler project is maintained by the Poppler developer community (https://poppler.freedesktop.org/).
