Create Fillable PDF Textbox via R

2019-05-02 08:44发布

问题:

I am using the test file from R Markdown, generated in RStudio by simple creating a new markdown file. It appears as follows:

---
title: "Fillable Textbox?"
author: "The Need To Edit"
date: "Wednesday, October 21, 2015"
output: pdf_document
---

  This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see <http://rmarkdown.rstudio.com>.

When you click the **Knit** button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:

```{r}
summary(cars)
```

You can also embed plots, for example:

```{r, echo=FALSE}
plot(cars)
```

Note that the `echo = FALSE` parameter was added to the code chunk to prevent printing of the R code that generated the plot.

My Question:

Is is possible to create a fillable textbox within the PDF form?

I am working to automate some of my workflow however within that automation the end user may need to add comments. I thought a fillable textbox would be a nice way to maintain a standard document format and give my users some freedom. I have found ways to do nearly everything except add a fillable textbox, perhaps I am searching the wrong expression?

回答1:

The hyperref package (which is loaded automatically) allows fillable fields. It is just a matter of use its specific commands, which you can find here. Try this code (click on the right of the word Name).

---
title: "Fillable Textbox?"
author: "The Need To Edit"
date: "Wednesday, October 21, 2015"
output: pdf_document
---

Since Rmarkdown uses knitr and it loads automatically hyperref I think hat this should work.

In fact it is just a matter of use some \LaTeX\ commands of the hyperref package.

```{r, echo=FALSE}
plot(cars)
```


\begin{Form}
    \TextField{Name}
\end{Form}

Of course this PDF is fillable as a PDF, and then it will not work inside the RStudio (if you use it) PDF viewer.



标签: r pdf markdown