2

I have a PDF form which needs to be filled out with data in df, one file per row, in the manner explained in the picture.

How can I create a printable area that contains the PDF as background, and prints each column of df on a specific position, namely, its corresponding field?

Thanks!

enter image description here

Carmen Sandoval
  • 2,266
  • 5
  • 30
  • 46
  • This is a too broad of a question. You have no provided an example of what your pdf looks like. You have also not specified what the fields are. I am unsure if R can programmatically interact with a pdf file. The solution might be to generate the PDF file from scratch and then programmatically fill it.Look into `hyperref ` package. – Amar Apr 12 '18 at 05:59
  • R can print to pdf formats as graphical devices but I suspect you wnat to use the package and documentation features offered for the .Rmd format. That also supports pdf file creation. – IRTFM Apr 12 '18 at 06:29
  • I guess I would place specific words-codes at the spots in the pdf something like `**Position1**` for A1, A6, `**Position2**` for B1, B6 etc ... then I would "find and replace" those values with a vector of "input words". – Andre Elrico Apr 12 '18 at 06:58

1 Answers1

0

First we need to store in a pdf with filename "My File". If you want a different filename each time just loop. The "par(mfrow=...) will tell R the dimensions of the plot i.e.

pdf(paste("My File",".pdf",sep=""))
par(mfrow=c(1,1))

Then we can choose a plot to print with vertical and horizontal lines; if our df has dimensions nrow by ncol:

p1<-p2<-0
plot(p1,p2,type="n",xlim=c(0.19,4.78),ylim=c(0.252,5.75))
abline(v=c(1:4),h=c(1:5))
text((1/2)*seq(1,9,by=2),rep((1/2)*seq(1,11,2),each=6),c("P","R","I","N","T"),cex=5)

Although I highly recommend you just use a package if possible such as in this short video: https://www.youtube.com/watch?v=GOQ_StD4sGA

Tony Hellmuth
  • 290
  • 2
  • 11