ablaette / learningR

Course taught at the University of Duisburg-Essen to get started with R.
Creative Commons Attribution 4.0 International
2 stars 3 forks source link

Problem pdf laden #7

Open OliverHamann1027 opened 4 years ago

OliverHamann1027 commented 4 years ago

Das Wahlprogramm der AfD zur Bundestagswahl 2017 kann nicht geladen werden.

afd_btw2017 <- "https://cdn.afd.tools/wp-content/uploads/sites/111/2017/08/AfD_Wahlprogramm_2017_A5-hoch.pdf"
afd_btw2017_local <- tempfile ()
download.file(url = afd_btw2017, destfile = afd_btw2017_local)

install.packages("pdftools")
library(pdftools)
pdftools::pdf_info(afd_btw2017_local)
txt <- pdftools::pdf_text(afd_btw2017_local) # Fehlermeldungen

is(txt)
length(txt)
txt[30] # kein Text wird erkannt

pdftools::pdf_info(afd_btw2017_local)

Fehler: PDF error (3490): Illegal character '{' PDF error: xref num 367 not found but needed, try to reconstruct<0a> $version

ablaette commented 4 years ago

Leider kann ich den Fehler nicht reproduzieren (MacOS, R Version 4.0). Beim Laden von pdftools wird angezeigt, dass poppler-Version 0.73.0 genutzt wird. Welche Version sehen Sie? Welche Version von pdftools nutzen Sie?

alexandranaumann commented 4 years ago

Ein Hinweis auf ein mögliches Problem

files <- list.files(pattern = "pdf$")

NOTE: the code above only works if you have your working directory set to the folder where you downloaded the PDF files. A quick way to do this in RStudio is to go to Session…Set Working Directory.

Link: https://data.library.virginia.edu/reading-pdf-files-into-r-for-text-mining/

ablaette commented 4 years ago

Wenn das Arbeitsverzeichnis (working directory) identisch sein muss mit dem Verzeichnis, in dem das pdf-Dokument liegt, dann könnte das hier funkionieren.

library(pdftools)

afd_btw2017 <- "https://cdn.afd.tools/wp-content/uploads/sites/111/2017/08/AfD_Wahlprogramm_2017_A5-hoch.pdf"
afd_btw2017_local <- tempfile()
download.file(url = afd_btw2017, destfile = afd_btw2017_local)

getwd() # das wird nicht das temporäre Verheichnis sein
setwd(tempdir()) # Arbeitsverzeichnis setzen! 
pdftools::pdf_info(afd_btw2017_local)
txt <- pdftools::pdf_text(afd_btw2017_local) # Fehlermeldungen