Golang有用于将doc转换为docx和将docx转换为pdf的包吗?

huangapple go评论75阅读模式
英文:

Golang packages for doc to docx and docx to pdf convertion?

问题

我正在使用Golang编写一个Web应用程序,用户可以上传doc或docx文件。根据预定义的格式,文件的某些内容将被更改。稍后,用户可以以docx或pdf格式下载更改后的文件。目前,我的应用程序只接受docx文件,根据预定义的格式更改文件,并让用户以docx格式下载。在Golang中是否有可用的包来将doc转换为docx和将docx转换为pdf?

英文:

I am writing a web application in Golang, in which user can upload a doc or docx file. Some of the file contents will be changed according to a predefined format. Later user can download the changed file either in docx or in pdf format. Now my application accepts only docx file, change the file according to predefined format and let the user download it back in docx format itself. Are there any packages available in golang to convert doc to docx and docx to pdf?

答案1

得分: 3

由于我正在使用Linux Ubuntu操作系统,Hugo的回答对我没有帮助(但我推荐Windows用户使用)。但是,这给了我解决这个问题的思路。codefreak在问题的评论中给了我一个清晰的图像。我同时采纳了他们的建议,结果是使用LibreOffice进行转换。

arg0 := "lowriter"
arg1 := "--invisible" //这个命令是可选的,它将帮助禁用LibreOffice的启动画面。
arg2 := "--convert-to"
arg3 := "pdf:writer_pdf_Export"
path := "/home/user/Test.docx"
nout, err := exec.Command(arg0,arg1,arg2,arg3,path).Output()

这段代码将调用LibreOffice并将.docx文件转换为.pdf文件。据我所知,这是最简单的方法。请发布其他可能帮助未来读者的答案。

英文:

As I am using linux ubuntu OS Hugo's answer didn't help me(But I recommend it for the windows users). But it gave me an idea about how to solve this problem. codefreak's comment on the question gave me a clear picture. I used both of their advice and result was the use of LibreOffice for the convertion.

arg0 := "lowriter"
arg1 := "--invisible" //This command is optional, it will help to disable the splash screen of LibreOffice.
arg2 := "--convert-to"
arg3 := "pdf:writer_pdf_Export"
path := "/home/user/Test.docx"
nout, err := exec.Command(arg0,arg1,arg2,arg3,path).Output()

This code will call LibreOffice and convert .docx file into .pdf. This is the easiest method as far as I know. Please post other answers which may help future readers.

答案2

得分: 2

这将在Windows上运行,因为它使用了Windows函数。

https://github.com/piaobocpp/doc2pdf-go

英文:

This will work over windows, as it is using the windows functions

https://github.com/piaobocpp/doc2pdf-go

huangapple
  • 本文由 发表于 2016年3月30日 13:37:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/36300515.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定