convert pdf (with special characters) to text

Viewed 521

Hi I'm trying to convert multiple pdfs to text, my code is working, however most of mine file are in spanish, with characters such as (ñ,í,ó,ú,é) and these (ñ,í,ó,ú,é) are getting corrupted. Also I need the text file to be in lower case for text analysis later:

library(XML)
  library(httr)
  library(dplyr)
  library(tidyr)
  library(stringr)
  library(tm)

  # Get a list of all of the document names of the downloaded PDFs
    pdf_files <- list.files(path = paste(getwd(), '/pdf', sep = ''),
                            pattern = 'pdf',
                            full.names = TRUE)

    # Check there are pdf files in directory
    if( length(pdf_files) > 0 ){

      # Loop through each PDF and create a txt version in the same folder

      for(i in pdf_files){

        system(
          paste(
            paste('"', getwd(), '/dependencies/xpdf/bin64/pdftotext.exe"', sep = ''), 
            paste0('"', i, '"')),
          wait = FALSE)

      }
    }


  cat( '\nConversion to text complete.\n\n' )
0 Answers
Related