-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathR_Read_PDF_and_OCR_Public.R
More file actions
32 lines (21 loc) · 904 Bytes
/
Copy pathR_Read_PDF_and_OCR_Public.R
File metadata and controls
32 lines (21 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Read PDF in RStudio
# https://bookdown.org/kochiuyu/Technical-Analysis-with-R/pdf-files.html
# https://library.virginia.edu/data/articles/reading-pdf-files-into-r-for-text-mining
library(pdftools)
# Set working directory to source file location first
txt <- pdf_text('2022_Varshney_TrustworthyML-Book.pdf')
length(txt) # The PDF has 267 pages
test <- txt[16] # Page 16
rows<-scan(textConnection(test), what="character", sep = "\n")
# ---------------------------------------------------------------
# OCR (Optical Character Recognition)
# https://reintech.io/blog/mastering-optical-character-recognition-r
# https://www.geeksforgeeks.org/optical-character-recognition-ocr-using-r/
library(tesseract)
library(magick)
# The text is "This text is easy to extract."
img <- image_read('easy_text_ocr.png')
print(img)
img_text <- ocr(img)
print(img_text)
# [1] "This text is\neasy to extract.\n"