diff --git a/.Rbuildignore b/.Rbuildignore
index 9dccaa1..ba2b29f 100644
--- a/.Rbuildignore
+++ b/.Rbuildignore
@@ -11,3 +11,4 @@
^docs$
^pkgdown$
^man/figures/logo\.png$
+img
diff --git a/DESCRIPTION b/DESCRIPTION
index 34554af..039e35c 100644
--- a/DESCRIPTION
+++ b/DESCRIPTION
@@ -24,7 +24,7 @@ Description: Provides function to manipulate PDF files:
SystemRequirements: Java 8 or higher
License: GPL-3
LazyData: true
-RoxygenNote: 7.1.1
+RoxygenNote: 7.1.2
Imports:
tcltk,
stringr,
diff --git a/NAMESPACE b/NAMESPACE
index 0118021..59ba89e 100644
--- a/NAMESPACE
+++ b/NAMESPACE
@@ -1,8 +1,7 @@
# Generated by roxygen2: do not edit by hand
-export(combine_pdf)
export(get_fields)
-export(idenfity_form_fields)
+export(identify_form_fields)
export(remove_pages)
export(rename_files)
export(rotate_pages)
@@ -11,6 +10,7 @@ export(select_pages)
export(set_fields)
export(split_from)
export(split_pdf)
+export(staple_pages)
export(staple_pdf)
import(utils)
importFrom(assertthat,assert_that)
diff --git a/R/combine_pdf.R b/R/staple_pages.R
similarity index 54%
rename from R/combine_pdf.R
rename to R/staple_pages.R
index f2f9639..ff84b44 100644
--- a/R/combine_pdf.R
+++ b/R/staple_pages.R
@@ -4,39 +4,40 @@
#' @importFrom pdftools pdf_subset pdf_combine pdf_length
#' @importFrom purrr map2_dbl walk2 flatten_dbl map_if
#' @importFrom fs file_temp file_temp_push path_ext_remove path_file
-#' @param vec_input Vector with paths of PDF files to be combined.
-#' @param output PDF file path result of the combination.
+#' @param input_files Vector with paths of PDF files to be combined.
+#' @param output_filepath PDF file path result of the combination.
#' @param start_pages Vector with the initial pages of each file. If \code{NA},
#' the default, will be considered the first page.
#' @param end_pages Vector with the final pages of each file. If \code{NA}, the
#' default, will be considered the last page.
#' @return
-#' In the path informed in \code{output}, the PDF file resulting from the combination
-#' of multiple files passed to \code{vec_output} will be saved.
+#' In the path informed in \code{output_filepath}, the PDF file resulting from the combination
+#' of multiple files passed to \code{input_files} will be saved.
+#' @author Pedro Rafael D. Marinho
#' @export
#' @examples
#'
#' \dontrun{
-#' combine_pdf(
-#' vec_input =
+#' staple_pages(
+#' input_files =
#' c(
#' "file_1.pdf",
#' "file_2.pdf",
#' ),
-#' output = "output.pdf",
+#' output_filepath = "output.pdf",
#' start_pages = c(NA, NA),
#' end_pages = c(NA, NA)
#' )
#' }
-combine_pdf <- function(vec_input, output = "output.pdf", start_pages = NA, end_pages = NA) {
+staple_pages <- function(input_files, output_filepath = "output.pdf", start_pages = NA, end_pages = NA) {
- if(length(start_pages) != length(vec_input) || length(end_pages) != length(vec_input))
- stop("Start_pages and end_pages must be a vector of the same length as vec_input!")
+ if(length(start_pages) != length(input_files) || length(end_pages) != length(input_files))
+ stop("Start_pages and end_pages must be a vector of the same length as input_files!")
start_pages <-
- flatten_dbl(
- map_if(
+ purrr::flatten_dbl(
+ purrr::map_if(
.x = start_pages,
.f = function(x) 1,
.p = is.na
@@ -46,37 +47,37 @@ combine_pdf <- function(vec_input, output = "output.pdf", start_pages = NA, end_
f <- function(x, y)
ifelse(
is.na(x),
- pdf_length(vec_input[y]),
+ pdftools::pdf_length(input_files[y]),
x
)
end_pages <-
purrr::map2_dbl(
.x = end_pages,
- .y = seq_along(vec_input),
+ .y = seq_along(input_files),
.f = f
)
files <-
- file_temp_push(
+ fs::file_temp_push(
glue(
- "{tempdir()}/{path_ext_remove(path_file(output))}_{1L:length(vec_input)}.pdf"
+ "{tempdir()}/{fs::path_ext_remove(fs::path_file(output_filepath))}_{1L:length(input_files)}.pdf"
)
)
one_step <- function(x, y) {
- pdf_subset(
+ pdftools::pdf_subset(
input = x,
- output = file_temp(),
+ output = fs::file_temp(),
pages = start_pages[y]:end_pages[y]
)
}
- walk2(
- .x = vec_input,
- .y = 1L:length(vec_input),
+ purrr::walk2(
+ .x = input_files,
+ .y = 1L:length(input_files),
.f = ~ one_step(.x, .y)
)
- pdf_combine(input = files, output = output)
+ pdftools::pdf_combine(input = files, output = output_filepath)
}
diff --git a/README.Rmd b/README.Rmd
index 07b7938..5df29e4 100644
--- a/README.Rmd
+++ b/README.Rmd
@@ -2,7 +2,7 @@
output: github_document
---
-# staplr
+# staplr
[](http://www.repostatus.org/#active)
[](https://www.gnu.org/licenses/gpl-3.0.en.html)
diff --git a/README.md b/README.md
index fbe4da0..f524da7 100644
--- a/README.md
+++ b/README.md
@@ -1,5 +1,5 @@
-# staplr
+# staplr
[](http://www.repo
[](https://travis-ci.org/pridiltal/staplr)
------
+------------------------------------------------------------------------
-[](https://cran.r-project.org/web/packages/staplr/index.html)
+[](https://cran.r-project.org/web/packages/staplr/index.html)
[](http://cran.rstudio.com/web/packages/staplr/index.html)
------
+------------------------------------------------------------------------
-[](/commits/master)
+[](/commits/master)
@@ -23,16 +23,16 @@ Status](https://travis-ci.org/pridiltal/staplr.svg?branch=master)](https://travi
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()
+- 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*.
@@ -107,31 +107,29 @@ set_fields(pdfFile, 'newFile.pdf', fields)
## Troubleshooting and 2.11.0 changes
- - As of version 2.11.0, the package uses
+- As of version 2.11.0, the package uses
[pdftk-java](https://gitlab.com/pdftk-java/pdftk) instead of using
the original
[pdftk](https://www.pdflabs.com/tools/pdftk-the-pdf-toolkit/).
`pdftk-java` is included with the package so if you have a working
java installation, you shouldn’t have any problems.
- - While default java options should be enough for most use cases, if
+- While default java options should be enough for most use cases, if
you need to, you can change java options that is used to run pdftk
by doing
-
-
``` r
options('staplr_java_options' = '-Xmx512m')
```
This option is not affected by `rJava` settings.
- - If you don’t have a working java installation, your installation
+- If you don’t have a working java installation, your installation
will fail since you can’t install rJava. Make sure you follow the
proper instructions for java installation. For openJDK on linux make
sure you get both jdk and jre and run javareconf.
-
+
sudo apt update -y
sudo apt install -y openjdk-8-jdk openjdk-8-jre
@@ -139,14 +137,12 @@ This option is not affected by `rJava` settings.
Also restart your R session after `javareconf`
- - `pdftk-java` is built as a faithful representation of the original
+- `pdftk-java` is built as a faithful representation of the original
`pdftk` so there shouldn’t be any major differences between the
outputs. However, for any reason you’d prefer to run a local
installation of pdftk rather than using the version that is shipped
with the package, do
-
-
``` r
# set staplr_custom_pdftk to the path to local installation
# just setting to pdftk will do if it's already in your path
@@ -164,4 +160,4 @@ in pdftk later.
## References
- -
+-
diff --git a/_pkgdown.yml b/_pkgdown.yml
index 6ef5f5a..9592b12 100644
--- a/_pkgdown.yml
+++ b/_pkgdown.yml
@@ -1 +1,7 @@
destination: docs
+opengraph:
+ image:
+ src: "logo.png"
+template:
+ params:
+ bootswatch: united
diff --git a/docs/404.html b/docs/404.html
index d971d28..7da3ae3 100644
--- a/docs/404.html
+++ b/docs/404.html
@@ -19,8 +19,8 @@
+
-
@@ -79,7 +79,7 @@
staplr
- 3.0.0
+ 3.2.0
@@ -87,7 +87,7 @@
diff --git a/docs/favicon-16x16.png b/docs/favicon-16x16.png
index d318d2b..a4c9b4d 100644
Binary files a/docs/favicon-16x16.png and b/docs/favicon-16x16.png differ
diff --git a/docs/favicon-32x32.png b/docs/favicon-32x32.png
index 438e4c0..c280c61 100644
Binary files a/docs/favicon-32x32.png and b/docs/favicon-32x32.png differ
diff --git a/docs/favicon.ico b/docs/favicon.ico
index ba264f7..1074d29 100644
Binary files a/docs/favicon.ico and b/docs/favicon.ico differ
diff --git a/docs/index.html b/docs/index.html
index 2ffa34c..33b45f2 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -12,7 +12,7 @@
-
+
@@ -28,7 +28,7 @@
Select pages from a file;
splits single input PDF document into individual pages;
splits single input PDF document into parts from given points.
- staplr requires a Java installation on your system.">
+ staplr requires Java 8 installed on your system.">
@@ -116,60 +116,56 @@
Installation
staplr requires a Java installation on your system. You can get the latest version of java from here. OpenJDK also works.
+library(staplr)# Merge multiple PDF files into one
-staple_pdf()
+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))
+remove_pages(rmpages =c(2,3))# This function selects pages from a file;
-select_pages(selpages = c(1,3))
+select_pages(selpages =c(1,3))# This function splits a single input PDF document into individual pages
-split_pdf()
+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))
+rename_files(new_names =paste("file",1:3))# These functions are to fill out pdf forms
-get_fields()
-set_fields()
+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
-
+# This is what the example file looks like
-
-# If you get path to this file by
-pdfFile=system.file('testForm.pdf',package = 'staplr')
+
+# If you get path to this file by
+pdfFile=system.file('testForm.pdf',package ='staplr')# And do
-fields=get_fields(pdfFile)
+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)
+fields$TextField1$value='this is text'
+set_fields(pdfFile, 'newFile.pdf', fields)
-# This will create a filled pdf file
-
+# This will create a filled pdf file
@@ -179,26 +175,24 @@
As of version 2.11.0, the package uses pdftk-java instead of using the original pdftk. pdftk-java is included with the package so if you have a working java installation, you shouldn’t have any problems.
While default java options should be enough for most use cases, if you need to, you can change java options that is used to run pdftk by doing
If you don’t have a working java installation, your installation will fail since you can’t install rJava. Make sure you follow the proper instructions for java installation. For openJDK on linux make sure you get both jdk and jre and run javareconf.
pdftk-java is built as a faithful representation of the original pdftk so there shouldn’t be any major differences between the outputs. However, for any reason you’d prefer to run a local installation of pdftk rather than using the version that is shipped with the package, do
-
-# set staplr_custom_pdftk to the path to local installation
+
+# 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.