0

Recently I have been tasked with creating a program that will be able to auto-fill a form using data from an Excel spreadsheet. I have chosen to do this in R, since I know it the best, and used the package officer to do so. The program works, is able to do this task quickly and at the end generates a .docx file with a personalized name. However, the person I am creating this program for would like to have these filled forms be saved as a .pdf file, with the personalized name still intact. Granted, there is an option to save them as .pdf in Word, but:

  1. this will slow down the process significantly with the volume of forms that will be generated.
  2. I am not interested in keeping the .docx files; I just want the PDFs.

What are possible solutions to this kind of issue? I know there exists one that requires installation of LibreOffice, but I would like to avoid it, since I don't want to have to download a whole other office productivity software suite just to convert a bunch of files from one format to another. I would much rather prefer for a solution to be done just within R, maybe with implementation of some other R package.

Here is how the process of saving filled forms looks right now:

setwd("*/Formularze") #changing the working directory to where I want to save the filled forms

print(formularz,
          target = glue::glue("Formularz - {inputs$name}.docx")) #saving the filled form with a unique name,
                                                                 #formularz is an object generated by
                                                                 #read_docx()

setwd("*") #returning to previous directory
Pawek-13
  • 3
  • 3
  • you can use `doconv::to_pdf()` if you have Word installed on your machine – David Gohel Jun 17 '23 at 18:00
  • @DavidGohel Can you show me how to implement it into my code? Because every time I try to run it, Iget an error message that my file cannot be converted because it cannot be found in the folder it is placed in? – Pawek-13 Jun 17 '23 at 19:39
  • @Pawek-13 try with the complete path. This command should be enough: `to_pdf(docx_file, output = "docx_example.pdf")`. – David Gohel Jun 17 '23 at 19:57
  • Looks like a "find a program to do X" sort of question. Specifically covered in one of the close justifications. – IRTFM Jun 18 '23 at 02:03

0 Answers0