Skip to content

This function signs a PDF document by calling the `BatchPDFSignPortable.jar` Java archive through a system command. It constructs a command to execute the JAR and sign the PDF based on the provided parameters, including keystore information, signature position, font size, and optionally signature text, reason for signing, and location of the signing.

Usage

sign_pdf(
  pdf_file,
  output_file,
  fs = 7,
  rh = 20,
  rw = 600,
  rx = 5,
  ry = 5,
  page = 1,
  signtext = NULL,
  validate_link = NULL,
  keystore_path = Sys.getenv("KEYSTORE_PATH"),
  keystore_password = Sys.getenv("KEY_PASSWORD"),
  translate = FALSE
)

Arguments

pdf_file

A string representing the path to the input PDF file that needs to be signed.

output_file

A string representing the path where the signed PDF will be saved.

fs

A numeric value indicating the font size of the signature text. Default is 7.

rh

A numeric value representing the rectangle height of the signature area. Default is 20.

rw

A numeric value representing the rectangle width of the signature area. Default is 600.

rx

A numeric value representing the X coordinate of the signature's position. Default is 5.

ry

A numeric value representing the Y coordinate of the signature's position. Default is 5.

page

A numeric value indicating the page number where the signature will be placed. Default is 1.

signtext

An optional string representing the custom text to be included in the signature.

An optional string representing the link to a app to validate the document.

keystore_path

A string representing the path to the keystore (e.g., a .p12 file) containing the signing key and certificate. Defaults to the environment variable `KEYSTORE_PATH`.

keystore_password

A string representing the password for accessing the keystore. Defaults to the environment variable `KEY_PASSWORD`.

translate

A boolean indicating whether the signature text should be translated to Portuguese. Default is FALSE (English).

Value

The function does not return a value but generates a signed PDF at the specified output path. If any error occurs, it will stop and display an appropriate error message.

Examples

if (FALSE) { # \dontrun{
sign_pdf(
  pdf_file = "input.pdf",
  output_file = "signed_output.pdf",
  keystore_path = "keystore.p12",
  keystore_password = "password",
  signtext = "Digitally signed by Company",
  validate_link = "apps.sepe.pe.gov.br/validate",
  translate = TRUE,
)
} # }