I need to find the names of the fields of a PDF Form. I also want to fill the PDF. I would like to do it with R. I found that the staplr package is supposed to do the job. with the code that is in this Stackoverflow link: Filling PDF forms in R?
I installed staplr first from RStudio using Tools and Install Packages. Later, I used devtools::install_github('pridiltal/staplr'). I installed Java and PDFtk Server that are requirements. However, after I installed staplr, I got the following errors:
Error: package or namespace load failed for ‘staplr’: .onLoad failed in loadNamespace() for 'staplr', details: call: NULL error: .onLoad failed in loadNamespace() for 'rJava', details: call: fun(libname, pkgname) error: JAVA_HOME cannot be determined from the Registry
Can I do it with any other R package?
I am trying to get the names of the field names of the PDF that is in this GitHub depository: https://github.com/silvestremilkman/SAAR
@AllanCameron suggested me to use the library pdftools
I found this link: https://ropensci.org/blog/2018/12/14/pdftools-20/
Based on that I have this code that is reading the PDF but, I am not getting the fields. I also do not know how to fill the fields. If you know, please publish an answer!
library(pdftools)
txt <- pdf_text("SAAR.pdf")
cat(txt[1])
If I use what the websites suggests to get a table, pdf_data instead of pdf_text, I get the following error:
pdf_data(txt)[[1]]
Error in normalizePath(path.expand(path), winslash, mustWork)
@OganM suggested that the staplr package would work uninstalling Java-32-bits and installing Java-64-bits. Jave-32-bits is the one that is installed by default when you download Java. Of course, if you do not have Java, the staplr package will not work. Thank you OganM!
So here is the code that is working to get the PDF field names.
library(staplr)
setwd("C:/Users/localadmin/Desktop")
fields = get_fields("SAAR.pdf")
fields
write.table(fields, file = "fields2.txt", sep = "
", row.names = FALSE)
See Question&Answers more detail:os