PDF Toolkit. 📎 🔨 🔧 ✂️ 📑 📁📎 🔖 🚧 👷
Branch: master
Clone or download
Latest commit 5125632 Feb 12, 2019



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




This package provides functions to manipulate PDF files:

  • fill out PDF forms: get_fields() and set_fields()
  • merge multiple PDF files into one: staple_pdf()
  • remove selected pages from a file: remove_pages()
  • rename multiple files in a directory: rename_files()
  • rotate entire pdf document: rotate_pdf()
  • rotate selected pages of a pdf file: rotate_pages()
  • Select pages from a file: select_pages()
  • splits single input PDF document into individual pages: split_pdf()
  • splits single input PDF document into parts from given points: split_from()

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


First Install pdftk

download and install pdftk. This is not an R package!

NB: pdftk is known to hang indefinitely on macOS High Sierra. If this happens to you, this version should work for macOS El Capitan (10.11), it also works on Sierra (10.12) and High Sierra (10.13).

Installation instructions for Red Hat or CentOS distributions can be found here: https://www.pdflabs.com/docs/install-pdftk-on-redhat-or-centos/

Packaged versions can be found for Arch and Ubuntu. On Ubuntu, for example, this means pdftk can be installed with the following command on most versions:

sudo apt install pdftk

Then Install staplr

You can install the stable version from CRAN.

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

You can install staplr from github with:

# install.packages("devtools")


# Merge multiple PDF files into one

# 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

# 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
# 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