如何将docx转换为PDF? [英] How to convert docx to PDF?
问题描述
我想问是否可以使用 R 将文本文件(如 word 文档或文本文档)转换为 PDF ?我想过将其转换为 .rmd,然后使用此代码转换为 PDF
I want to ask if it is possible to convert text files such as word document or text document to PDF using R ? I thought of converting it to .rmd and then to PDF using this code
require(rmarkdown)
my_text <- readLines("C:/.../track.txt")
cat(my_text, sep="
", file = "my_text.Rmd")
render("my_text.Rmd", pdf_document())
但显示此错误不起作用:
But it doesn't work showing this error:
> 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
的位置以及输入和输出文件路径和名称,适当更改前三行.
.txt to .pdf
Install wkhtmltopdf and then from R run the following. Change the first three lines as appropriate depending on where wkhtmltopdf
is on your system and depending on the input and output file paths and names.
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,根据需要修改下面前三行并运行.效果如何取决于您的输入.
.docx to .pdf
Install pandoc, modify the first three lines below as needed and run. How well this works may vary depending on your input.
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)
这篇关于如何将docx转换为PDF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!