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 [![Project Status: Active - The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![Licence](https://img.shields.io/badge/licence-GPL--3-blue.svg)](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 [![Project Status: Active - The project has reached a stable, usable state and is being actively @@ -8,14 +8,14 @@ developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repo [![Build Status](https://travis-ci.org/pridiltal/staplr.svg?branch=master)](https://travis-ci.org/pridiltal/staplr) ------ +------------------------------------------------------------------------ -[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/staplr)](https://cran.r-project.org/web/packages/staplr/index.html) +[![CRAN_Status_Badge](http://www.r-pkg.org/badges/version/staplr)](https://cran.r-project.org/web/packages/staplr/index.html) [![](http://cranlogs.r-pkg.org/badges/staplr)](http://cran.rstudio.com/web/packages/staplr/index.html) ------ +------------------------------------------------------------------------ -[![Last-changedate](https://img.shields.io/badge/last%20change-2020--07--21-yellowgreen.svg)](/commits/master) +[![Last-changedate](https://img.shields.io/badge/last%20change-2021--09--27-yellowgreen.svg)](/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 @@