staplr

Project Status: Active - The project has reached a stable, usable state and is being actively developed. Licence Build Status


CRAN_Status_Badge


Last-changedate

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "README-"
)

staplr

This package provides functions to manipulate PDF files:

This package is still under development and this repository contains a development version of the R package staplr.

Installation

staplr requires a Java installation on your system. You can get the latest version of java from here. OpenJDK also works.

You can install the stable version from CRAN.

install.packages('staplr', dependencies = TRUE)

You can install staplr from github with:

# install.packages("devtools")
devtools::install_github("pridiltal/staplr")

Example

library(staplr)
# Merge multiple PDF files into one
staple_pdf()

# This command prompts the user to select the file interactively. 
# Remove page 2 and 3 from the selected file.
remove_pages(rmpages = c(2,3))

# This function selects pages from a file;
select_pages(selpages = c(1,3))

# This function splits a single input PDF document into individual pages
split_pdf()

# This function writes renamed files back to directory
#if the directory contains 3 PDF files
rename_files(new_names = paste("file",1:3))

# These functions are to fill out pdf forms
get_fields() 
set_fields()
# This includes 2 external functions `get_fields` and `set_fields` 
# and files to use as examples.
# This is what the example file looks like

# If you get path to this file by
pdfFile = system.file('testForm.pdf',package = 'staplr')

# And do
fields = get_fields(pdfFile)
# You'll get a list of fields that the pdf contains 
# along with some additional information about the fields.

# You make modifications in any of the fields by
fields$TextField1$value = 'this is text'
set_fields(pdfFile, 'newFile.pdf', fields)

# This will create a filled pdf file

Troubleshooting and 2.11.0 changes

options('staplr_java_options' = '-Xmx512m') 

This option is not affected by rJava settings.

sudo apt update -y
sudo apt install -y openjdk-8-jdk openjdk-8-jre
sudo R CMD javareconf

Also restart your R session after javareconf

# set staplr_custom_pdftk to the path to local installation
# just setting to pdftk will do if it's already in your path
 options('staplr_custom_pdftk' = 'pdftk') 

If you want to do this, you can get the original version of pdftk from here. Note that MacOS users with a version higher than "High Sierra" should use this version instead.

Make sure to set the option back to NULL if you want to use the built in pdftk later.

References



pridiltal/staplr documentation built on Jan. 26, 2024, 9:11 a.m.