微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Rshiny,下载处理程序,如何将 word docx 转换为 pdf 并在下载处理程序中下载 pdf

如何解决Rshiny,下载处理程序,如何将 word docx 转换为 pdf 并在下载处理程序中下载 pdf

我是 Rshiny 的新手,在将 .docx 文件(由官员生成)转换为 .pdf 时遇到了麻烦。 .docx 文件生成没有任何错误,但我不确定如何使用 downloadhandler 下载同一 .docx 文档的 pdf 文件。下面是我用来首先将 .docx 转换为 .pdf 然后使用 downloadhandler 下载 pdf 文件代码。请帮我更正下载pdf文件代码

observeEvent(
  input$GenerateProtcolDocument_individual,{
    reportname_individual <-
      genReport_individual()#function to generate word document using officer package
    
    doc_list_individual <- length(reportname_individual)
    url_doc_individual <- list()
    
    office_shot <-
      function(wd = getwd(),file) {
        # function to convert word docx to pdf
        cmd_ <- sprintf("C:/Program Files/LibreOffice/program/soffice.exe",wd,file)
        system(cmd_)
        
        pdf_file <- gsub("\\.(docx|pptx)$",".pdf",basename(file))
        return (pdf_file)
      }
    my.file <- office_shot(file  = reportname_individual)
    
    for (i in 1:doc_list_individual) {
      url_doc_individual[[i]] <-
        a(reportname_individual[i],href = paste(reportname_individual[i],sep = ""))
      
    }
    output$reportlinks_individual <-
      renderUI({
        #This works as required creates hyperlink of the documents
        
        Box(
          p("Click the link to download individual document"),br(),url_doc_individual,width = 12
        )
      })
    
    
    output$Download_pdf <- downloadHandler(
      filename = function() {
        paste("data-",Sys.Date(),sep = "")
      },content = function(file) {
        pdf(my.file,file) #my.file is the pdf file returned from **office_shot** function
        dev.off()
        
      }
    )
  
})

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。