Staplr PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 16

Package ‘staplr’

February 13, 2019


Type Package
Title A Toolkit for PDF Files
Version 2.9.0
Depends R (>= 3.4.0)
Maintainer Priyanga Dilini Talagala <dilini.talagala@monash.edu>
Description Provides function to manipulate PDF files:
fill out PDF forms;
merge multiple PDF files into one;
remove selected pages from a file;
rename multiple files in a directory;
rotate entire pdf document;
rotate selected pages of a pdf file;
Select pages from a file;
splits single input PDF document into individual pages;
splits single input PDF document into parts from given points.
License GPL-3
LazyData true
RoxygenNote 6.1.1
Imports tcltk, stringr, assertthat, glue
Suggests lattice, testthat, pdftools
Encoding UTF-8

BugReports https://github.com/pridiltal/staplr/issues
NeedsCompilation no
Author Priyanga Dilini Talagala [aut, cre],
Ogan Mancarci [aut],
Daniel Padfield [aut],
Granville Matheson [aut]
Repository CRAN
Date/Publication 2019-02-13 06:40:03 UTC

1
2 get_fields

R topics documented:
get_fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
idenfity_form_fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
remove_pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
rename_files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
rotate_pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
rotate_pdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
select_pages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
set_fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
split_from . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
split_pdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
staple_pdf . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
staplr . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

Index 16

get_fields Get form fields from a pdf form

Description
If the toolkit Pdftk is available in the system, it will be called to get form fields from a pdf file.
See the reference for detailed usage of pdftk.

Usage
get_fields(input_filepath = NULL)

Arguments
input_filepath the path of the input PDF file. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.

Value
A list of fields. With type, name and value components. To use with set_fields edit the value
element of the fields you want to modify. If the field of type "button", the value will be a factor. In
this case the factor levels describe the possible values for the field. For example for a checkbox the
typical level names would be "Off" and "Yes", corresponding to non checked and checked states
respectively.

Author(s)
Ogan Mancarci

References
https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
idenfity_form_fields 3

See Also

link{set_fields}

Examples
## Not run:
pdfFile = system.file('testForm.pdf',package = 'staplr')
fields = get_fields(pdfFile)

## End(Not run)

idenfity_form_fields Identify text form fields

Description

Helps identification of text forum fields by creating a file that is filled with field names. Some pdf
editors show field names when you mouse over the fields as well.

Usage

idenfity_form_fields(input_filepath = NULL, output_filepath = NULL,


overwrite = TRUE)

Arguments

input_filepath the path of the input PDF file. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.
output_filepath
the path of the output PDF file. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.
overwrite If a file exists in output_filepath, should it be overwritten.

Examples
## Not run:
pdfFile = system.file('testForm.pdf',package = 'staplr')
idenfity_form_fields(pdfFile, 'testOutput.pdf')

## End(Not run)
4 remove_pages

remove_pages Remove selected pages from a file

Description
If the toolkit Pdftk is available in the system, it will be called to remove the given pages from the
seleted PDF files.
See the reference for detailed usage of pdftk.

Usage
remove_pages(rmpages, input_filepath = NULL, output_filepath = NULL,
overwrite = TRUE)

Arguments
rmpages a vector of page numbers to be removed
input_filepath the path of the input PDF file. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.
output_filepath
the path of the output PDF file. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.
overwrite If a file exists in output_filepath, should it be overwritten.

Value
this function returns a PDF document with the remaining pages

Author(s)
Priyanga Dilini Talagala

References
https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/

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

## End(Not run)

## Not run:
dir <- tempdir()
rename_files 5

require(lattice)
for(i in 1:3) {
pdf(file.path(dir, paste("plot", i, ".pdf", sep = "")))
print(xyplot(iris[,1] ~ iris[,i], data = iris))
dev.off()
}
output_file <- file.path(dir, paste('Full_pdf.pdf', sep = ""))
staple_pdf(input_directory = dir, output_file)
input_path <- file.path(dir, paste("Full_pdf.pdf", sep = ""))
output_path <- file.path(dir, paste("trimmed_pdf.pdf", sep = ""))
remove_pages(rmpages = 1, input_path, output_path)

## End(Not run)

rename_files Rename multiple files

Description

Rename multiple files in a directory and write renamed files back to directory

Usage

rename_files(input_directory = NULL, new_names)

Arguments
input_directory
the path of the input PDF files. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.
new_names a vector of names for the output files.

Value

this function writes renamed files back to directory

Author(s)

Priyanga Dilini Talagala

References

https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
6 rotate_pages

Examples
## Not run:
#if the directory contains 3 PDF files
rename_files(new_names = paste("file",1:3))

## End(Not run)

rotate_pages Rotate selected pages of a pdf file

Description
If the toolkit Pdftk is available in the system, it will be called to rotate the given pages of the seleted
PDF files
See the reference for detailed usage of pdftk.

Usage
rotate_pages(rotatepages, page_rotation = c(0, 90, 180, 270),
input_filepath = NULL, output_filepath = NULL, overwrite = TRUE)

Arguments
rotatepages a vector of page numbers to be rotated
page_rotation An integer value from the vector c(0, 90, 180, 270). Each option sets the page
orientation as follows: north: 0, east: 90, south: 180, west: 270. Note that the
orientation cannot be cummulatively changed (eg. 90 (east) will always turn the
page so the beginning of the page is on the right side)
input_filepath the path of the input PDF file. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.
output_filepath
the path of the output PDF file. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.
overwrite If a file exists in output_filepath, should it be overwritten.

Value
this function returns a PDF document with the remaining pages

Author(s)
Priyanga Dilini Talagala

References
https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
rotate_pdf 7

Examples
## Not run:
# This command prompts the user to select the file interactively.
# Rotate page 2 and 6 to 90 degrees clockwise
rotate_pages(rotatepages = c(3,6), page_rotation = 90)

## End(Not run)

## Not run:
dir <- tempdir()
require(lattice)
for(i in 1:3) {
pdf(file.path(dir, paste("plot", i, ".pdf", sep = "")))
print(xyplot(iris[,1] ~ iris[,i], data = iris))
dev.off()
}
output_file <- file.path(dir, paste('Full_pdf.pdf', sep = ""))
staple_pdf(input_directory = dir, output_file)
input_path <- file.path(dir, paste("Full_pdf.pdf", sep = ""))
output_path <- file.path(dir, paste("Rotated_pgs_pdf.pdf", sep = ""))
rotate_pages(rotatepages = c(2,3), page_rotation = 90, input_path, output_path)

## End(Not run)

rotate_pdf Rotate entire pdf document

Description
If the toolkit Pdftk is available in the system, it will be called to rotate the entire PDF document
See the reference for detailed usage of pdftk.

Usage
rotate_pdf(page_rotation = c(0, 90, 180, 270), input_filepath = NULL,
output_filepath = NULL, overwrite = TRUE)

Arguments
page_rotation An integer value from the vector c(0, 90, 180, 270). Each option sets the page
orientation as follows: north: 0, east: 90, south: 180, west: 270. Note that the
orientation cannot be cummulatively changed (eg. 90 (east) will always turn the
page so the beginning of the page is on the right side)
input_filepath the path of the input PDF file. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.
output_filepath
the path of the output PDF file. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.
overwrite If a file exists in output_filepath, should it be overwritten.
8 select_pages

Value
this function returns a PDF document with the rotated pages

Author(s)
Priyanga Dilini Talagala

References
https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/

Examples
## Not run:
# This command prompts the user to select the file interactively.
# Rotate the entire PDF document to 90 degrees clockwise
rotate_pdf(page_rotation = 90)

## End(Not run)

## Not run:
dir <- tempdir()
require(lattice)
for(i in 1:3) {
pdf(file.path(dir, paste("plot", i, ".pdf", sep = "")))
print(xyplot(iris[,1] ~ iris[,i], data = iris))
dev.off()
}
output_file <- file.path(dir, paste('Full_pdf.pdf', sep = ""))
staple_pdf(input_directory = dir, output_file)
input_path <- file.path(dir, paste("Full_pdf.pdf", sep = ""))
output_path <- file.path(dir, paste("rotated_pdf.pdf", sep = ""))
rotate_pdf( page_rotation = 90, input_path, output_path)

## End(Not run)

select_pages Select pages from a file

Description
If the toolkit Pdftk is available in the system, it will be called to combine the selected pages in a
new pdf file.
See the reference for detailed usage of pdftk.

Usage
select_pages(selpages, input_filepath = NULL, output_filepath = NULL,
overwrite = TRUE)
select_pages 9

Arguments

selpages a vector of page numbers to be selected


input_filepath the path of the input PDF file. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.
output_filepath
the path of the output PDF file. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.
overwrite If a file exists in output_filepath, should it be overwritten.

Value

this function returns a PDF document with the remaining pages

Author(s)

Granville Matheson, Priyanga Dilini Talagala

References

https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/

Examples
## Not run:
# This command prompts the user to select the file interactively.
# Select page 3 and 6 from the selected file.
select_pages(selpages = c(3,6))

## End(Not run)

## Not run:
dir <- tempdir()
require(lattice)
for(i in 1:3) {
pdf(file.path(dir, paste("plot", i, ".pdf", sep = "")))
print(xyplot(iris[,1] ~ iris[,i], data = iris))
dev.off()
}
output_file <- file.path(dir, paste('Full_pdf.pdf', sep = ""))
staple_pdf(input_directory = dir, output_file)
input_path <- file.path(dir, paste("Full_pdf.pdf", sep = ""))
output_path <- file.path(dir, paste("trimmed_pdf.pdf", sep = ""))
select_pages(selpages = 1, input_path, output_path)

## End(Not run)
10 set_fields

set_fields Set fields of a pdf form

Description
If the toolkit Pdftk is available in the system, it will be called to fill a pdf form with given a list of
fields. List of fields can be acquired by get_fields function.
See the reference for detailed usage of pdftk.

Usage
set_fields(input_filepath = NULL, output_filepath = NULL, fields,
overwrite = TRUE)

Arguments
input_filepath the path of the input PDF file. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.
output_filepath
the path of the output PDF file. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.
fields Fields returned from get_fields function. To make changes in a PDF, edit the
values component of an element within this list
overwrite If a file exists in output_filepath, should it be overwritten.

Author(s)
Ogan Mancarci

References
https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/

See Also
get_fields

Examples
## Not run:
pdfFile = system.file('testForm.pdf',package = 'staplr')
fields = get_fields(pdfFile)

fields$TextField1$value = 'this is text'


fields$TextField2$value = 'more text'
fields$RadioGroup$value = 2
fields$checkBox$value = 'Yes'
split_from 11

set_fields(pdfFile,'filledPdf.pdf',fields)

## End(Not run)

split_from Splits single input PDF document into parts from given points

Description

If the toolkit Pdftk is available in the system, it will be called to Split a single input PDF document
into two parts from a given point
See the reference for detailed usage of pdftk.

Usage

split_from(pg_num, input_filepath = NULL, output_directory = NULL,


prefix = "part", overwrite = TRUE)

Arguments

pg_num A vector of non-negative integers. Split the pdf document into parts from the
numbered pages.
input_filepath the path of the input PDF file. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.
output_directory
the path of the output directory
prefix A string for output filename prefix
overwrite If a file exists in output_filepath, should it be overwritten.

Value

this function splits a single input PDF document into individual pages

Author(s)

Priyanga Dilini Talagala and Ogan Mancarci

References

https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/
12 split_pdf

Examples
## Not run:
# Split the pdf from page 10
split_from(pg_num=10)

## End(Not run)

## Not run:
dir <- tempdir()
require(lattice)
for(i in 1:4) {
pdf(file.path(dir, paste("plot", i, ".pdf", sep = "")))
print(xyplot(iris[,1] ~ iris[,i], data = iris))
dev.off()
}
staple_pdf(input_directory = dir, output_filepath = file.path(dir, 'Full_pdf.pdf'))
input_path <- file.path(dir, "Full_pdf.pdf")
split_from(pg_num=2, input_filepath = input_path ,output_directory = dir )

## End(Not run)

split_pdf Splits single input PDF document into individual pages.

Description
If the toolkit Pdftk is available in the system, it will be called to Split a single input PDF document
into individual pages.
See the reference for detailed usage of pdftk.

Usage
split_pdf(input_filepath = NULL, output_directory = NULL,
prefix = "page_")

Arguments
input_filepath the path of the input PDF file. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.
output_directory
the path of the output directory
prefix A string for output filename prefix

Value
this function splits a single input PDF document into individual pages
staple_pdf 13

Author(s)
Priyanga Dilini Talagala and Ogan Mancarci

References
https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/

Examples
## Not run:
split_pdf()

## End(Not run)

## Not run:
dir <- tempdir()
require(lattice)
for(i in 1:3) {
pdf(file.path(dir, paste("plot", i, ".pdf", sep = "")))
print(xyplot(iris[,1] ~ iris[,i], data = iris))
dev.off()
}
staple_pdf(input_directory = dir, output_filepath = file.path(dir, 'Full_pdf.pdf'))
split_pdf(input_filepath = file.path(dir, paste("Full_pdf.pdf", sep = "")),output_directory = dir )

## End(Not run)

staple_pdf Merge multiple PDF files into one

Description
If the toolkit Pdftk is available in the system, it will be called to merge the PDF files.
See the reference for detailed usage of pdftk.

Usage
staple_pdf(input_directory = NULL, input_files = NULL,
output_filepath = NULL, overwrite = TRUE)

Arguments
input_directory
the path of the input PDF files. The default is set to NULL. If NULL, it prompt
the user to select the folder interactively.
input_files a vector of input PDF files. The default is set to NULL. If NULL and input_directory
is also NULL, the user is propted to select a folder interactively.
14 staplr

output_filepath
the path of the output PDF file. The default is set to NULL. IF NULL, it prompt
the user to select the folder interactively.
overwrite If a file exists in output_filepath, should it be overwritten.

Value
this function returns a combined PDF document

Author(s)
Priyanga Dilini Talagala and Daniel Padfield

References
https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/

Examples
## Not run:
staple_pdf()

## End(Not run)

## Not run:
dir <- tempdir()
require(lattice)
for(i in 1:3) {
pdf(file.path(dir, paste("plot", i, ".pdf", sep = "")))
print(xyplot(iris[,1] ~ iris[,i], data = iris))
dev.off()
}
output_file <- file.path(dir, paste('Full_pdf.pdf', sep = ""))
staple_pdf(input_directory = dir, output_filepath = output_file)

## End(Not run)

staplr staplr: A package containing a toolkit for PDF files

Description
This package provides function to manipulate PDF files: merging multiple PDF files into one.

Author(s)
Priyanga Dilini Talagala, Ogan Mancarci and Daniel Padfield
staplr 15

References
https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/

See Also
The core functions in this package: staple_pdf, remove_pages, split_pdf, rename_files
Index

get_fields, 2, 10

idenfity_form_fields, 3

remove_pages, 4, 15
rename_files, 5, 15
rotate_pages, 6
rotate_pdf, 7

select_pages, 8
set_fields, 2, 10
split_from, 11
split_pdf, 12, 15
staple_pdf, 13, 15
staplr, 14
staplr-package (staplr), 14

16

You might also like