2

Not sure what I am doing wrong. I want to convert multiple docx.files to pdf.files - each file into a separate one. I decided to use the "doconv"-package with following command:


docx_files <- list.files(pattern=paste0("Protokollnr_"))[39:73]
docx_files %>% length

lapply(1:35, function(x) {
docx2pdf(input = docx_files[[x]],
         output =  tempfile(fileext = ".pdf"))})

I does not say anything specific in the error message - only that it cannot be converted. Is it that I should have specified the file path - now I only define the file name in my WD.

The object "docx_files" contain:

 c("Protokollnr_1.docx", "Protokollnr_10.docx", "Protokollnr_11.docx", 
    "Protokollnr_12.docx", "Protokollnr_13.docx", "Protokollnr_14.docx", 
    "Protokollnr_15.docx", "Protokollnr_16.docx", "Protokollnr_17.docx", 
    "Protokollnr_18.docx", "Protokollnr_19.docx", "Protokollnr_2.docx", 
    "Protokollnr_20.docx", "Protokollnr_21.docx", "Protokollnr_22.docx", 
    "Protokollnr_23.docx", "Protokollnr_24.docx", "Protokollnr_25.docx", 
    "Protokollnr_26.docx", "Protokollnr_27.docx", "Protokollnr_28.docx", 
    "Protokollnr_29.docx", "Protokollnr_3.docx", "Protokollnr_30.docx", 
    "Protokollnr_31.docx", "Protokollnr_32.docx", "Protokollnr_33.docx", 
    "Protokollnr_34.docx", "Protokollnr_35.docx", "Protokollnr_4.docx", 
    "Protokollnr_5.docx", "Protokollnr_6.docx", "Protokollnr_7.docx", 
    "Protokollnr_8.docx", "Protokollnr_9.docx")

The error message is:

Error in docx2pdf(input = docx_files[[x]], output = tempfile(fileext = ".pdf")) : 
  could not convert C:/Users/Nadine/OneDrive/Documents/Arbeit_Büro_papa/Protokolle_Sallapulka/fertige_Protokolle/Protokollnr_1.docx

Many thanks, Nadine

Nadiine El Nino
  • 339
  • 1
  • 6
  • How do you think we can be of assistance? Bottom line, without a file (and accepting that software often needs to improve its error messages) there is very little we can do. – r2evans Apr 21 '22 at 13:24
  • Sorry I thought someone could just tell me if I need to specify the file path for the docx.files. – Nadiine El Nino Apr 21 '22 at 14:15
  • Have you solved this problem? I've got the same problem. It works on a fils inside a given folder, but doesn't in another folder – Julien Apr 05 '23 at 09:04

2 Answers2

1

I'm encountering this error on Windows because running scripts isn't enabled.

Exploring the source code led me to uncover a more informative error message stating that the temporary script created by doconv "cannot be loaded because running scripts is disabled on this system."

Enabling scripts will require editing execution policies; details are at Microsoft's page about_Execution_Policies at https://go.microsoft.com/fwlink/?LinkID=135170.

Martin Smith
  • 3,687
  • 1
  • 24
  • 51
0

I'd recommend specifying the file path since the function requires the following format:

docx2pdf(input, output = gsub("\\.docx$", ".pdf", input))
Martin Gal
  • 16,640
  • 5
  • 21
  • 39
codable
  • 19
  • 7
  • 1
    How can I get the file path for each file? I have saved them all in one folder, – Nadiine El Nino Apr 21 '22 at 14:16
  • Perhaps I just go for paste0.. I do not know if there is a command where I could extract file paths by just typing in their filename - would be cool. – Nadiine El Nino Apr 21 '22 at 14:19
  • I'm not sure which operating system (e.g., Windows, Mac, Linux) you're using, but here is one way you can look for the file path for your files: https://www.sony.com/electronics/support/articles/00015251 – codable Apr 21 '22 at 14:26
  • Yes, I know this copy paste approach. Wondered if there was something more straightforward without copying but it's okay for now – Nadiine El Nino Apr 21 '22 at 14:45
  • filepath <- paste0(getwd(),"/") filename_with_path <- paste0(filepath,docx_files) – Nadiine El Nino Apr 21 '22 at 14:48
  • Okay I tried to change the input object...with no success "C:/Users/Nadine/Data/Protokollnr_32.docx" This is the file path that I use in the command docx2pdf together with gsub.. – Nadiine El Nino Apr 21 '22 at 14:54
  • the gsub command works so it must have something to do with the input format.. or my coding before??? – Nadiine El Nino Apr 21 '22 at 14:56
  • I'm not quite certain. I have to get going, but I did find a temporary alternative solution: https://stackoverflow.com/questions/49113503/how-to-convert-docx-to-pdf/49116745#49116745 (try using pandoc). – codable Apr 21 '22 at 15:15