gpt4 book ai didi

r - 如何将 docx 转换为 PDF?

转载 作者:行者123 更新时间:2023-12-04 16:07:16 25 4
gpt4 key购买 nike

我想问一下是否可以使用R将word文档或文本文档等文本文件转换为PDF?
我想使用此代码将其转换为 .rmd,然后转换为 PDF

require(rmarkdown)
my_text <- readLines("C:/.../track.txt")
cat(my_text, sep=" \n", file = "my_text.Rmd")
render("my_text.Rmd", pdf_document())
但它不起作用显示此错误:
> Error: Failed to compile my_text.tex.
In addition: Warning message:
running command '"pdflatex" -halt-on-error -interaction=batchmode "my_text.tex"' had status 127
还有其他解决方案吗?

最佳答案

.txt 到 .pdf

安装 wkhtmltopdf然后从 R 运行以下命令。根据 wkhtmltopdf 的位置酌情更改前三行位于您的系统上,取决于输入和输出文件路径和名称。

wkhtmltopdf <- "C:\\Program Files\\wkhtmltopdf\\bin\\wkhtmltopdf.exe"
input <- "in.txt"
output <- "out.pdf"
cmd <- sprintf('"%s" "%s" -o "%s"', wkhtmltopdf, input, output)
shell(cmd)

.docx 到 .pdf

安装 pandoc ,根据需要修改下面的前三行并运行。效果如何可能会因您的输入而异。
pandoc <- "C:\\Program Files (x86)\\Pandoc\\pandoc.exe"
input <- "in.docx"
output <- "out.pdf"
cmd <- sprintf('"%s" "%s" -o "%s"', pandoc, input, output)
shell(cmd)

关于r - 如何将 docx 转换为 PDF?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49113503/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com