我正在用Golang编写一个web应用程序,在这个应用程序中,用户可以上传一个文档或docx文件。一些文件内容将根据预定义的格式进行更改。以后,用户可以以docx或pdf格式下载修改后的文件。现在,我的应用程序只接受docx文件,根据预定义的格式更改文件,让用户以docx格式自己下载它。在golang中是否有任何软件包可以将doc转换为docx,docx转换为pdf?
发布于 2016-03-31 12:13:25
由于我正在使用linux,Hugo的回答并没有帮助我(但我推荐给windows用户)。但它给了我一个如何解决这个问题的想法。codefreak对这个问题的评论给了我一个清晰的印象。我使用了他们的建议和结果是使用LibreOffice进行转换。
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()此代码将调用LibreOffice并将.docx文件转换为.pdf。据我所知,这是最简单的方法。请张贴其他的答案,可能有助于未来的读者。
发布于 2016-03-30 13:26:43
这将适用于windows,因为它使用的是windows函数。
https://stackoverflow.com/questions/36300515
复制相似问题