convertpdf2txt <- function(dirpath){

   files <- list.files(dirpath, pattern = "Consoli.*\\.pdf$", full.names
= TRUE)
   files <- chartr("\\", "/", files)

   x <- lapply(files, function(x){
     pdftools::pdf_text(x) %>%
       paste0(collapse = " ") %>%
       stringr::str_squish()
   })
   new_names <- tools::file_path_sans_ext(files)
   new_names <- paste(new_names, "txt", sep = ".")
   setNames(x, new_names)
}

# apply function
# note that my test files are in "~/Temp"
txts <- convertpdf2txt(here::here("~", "Temp"))
names(txts)


Thank you very much, but the following error appeared:

Error: unexpected '}' in "}"




Cec�lia Carmo

Universidade de Aveiro

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to