[英]How to use unoconv with a newer version of libreoffice
I am trying to convert encrypted documents (doc/docx) into PDF using python.我正在尝试使用 python 将加密文档 (doc/docx) 转换为 PDF。
What I do is:我要做的是:
unoconv -f pdf -eSelectPdfVersaion=1 [path-to-file]
The conversion runs, but I notice that in the doc and docx files there is a change in the appearance of the documents (both the decrypted file and the pdf) which does not affect the original encrypted file (I tested it by simply decrypting the file from a windows client and the decrypted file as it originally was).转换运行,但我注意到在 doc 和 docx 文件中,文档(解密文件和 pdf)的外观发生了变化,这不会影响原始加密文件(我通过简单地解密文件对其进行了测试)来自 Windows 客户端和原始解密文件)。
The appearance is basically a change in the document style which affects the amount of pages.外观基本上是影响页面数量的文档样式的变化。 For example a 13-pages Word document is decrypted into 14-pages of Word document and converted to a PDF file of 14 pages.例如一个13页的Word文档被解密成14页的Word文档,并转换成一个14页的PDF文件。 Similarly a 348-page doc file gets converted into a 330-pages doc file and then a 330-pages PDF file.类似地,一个 348 页的 doc 文件被转换为一个 330 页的 doc 文件,然后是一个 330 页的 PDF 文件。
I discovered that there is a slight incompatibility of styles between Microsoft Word and the version of LibreOffice installed with Unoconv (4.3).我发现 Microsoft Word 和随 Unoconv (4.3) 安装的 LibreOffice 版本之间的样式略有不兼容。 Doing my tests I noticed that fonts get changed to LibreOffice compatible ones that are slightly different in size than the original ones.在做我的测试时,我注意到字体被更改为 LibreOffice 兼容的字体,它们的大小与原始字体略有不同。
I installed a later version of LibreOffice (5.1, 5.3) and in my tests the decrypted doc/docx file had the proper formatting and page numbers, but the unoconv does not utilize the newer version and sticks to 4.3, thus producing the PDF file with incorrect styling and pages number.我安装了更高版本的 LibreOffice(5.1、5.3),并且在我的测试中,解密的 doc/docx 文件具有正确的格式和页码,但 unoconv 不使用较新版本并坚持使用 4.3,因此生成的 PDF 文件为不正确的样式和页码。
I tried to use the:我尝试使用:
soffice --headless --convert-to pdf [path-to-file] --outdir [path-to-export-directory]
But it does nothing.但它什么也不做。
Is there a way to utilize unoconv with a LibreOffice version other than the 4.3?有没有办法在 4.3 以外的 LibreOffice 版本中使用 unoconv?
Is there a way to make the --convert-to command to work with LibreOffice 5.1 or even 5.3?有没有办法让 --convert-to 命令与 LibreOffice 5.1 甚至 5.3 一起使用?
Here are few steps you could try: Uninstall the older version of libreoffice using以下是您可以尝试的几个步骤: 使用卸载旧版本的 libreoffice
sudo apt remove libreoffice*
Install the latest version of libreoffice using使用安装最新版本的 libreoffice
sudo add-apt-repository ppa:libreoffice/ppa
sudo apt-get update
sudo apt-get install libreoffice
To check if libreoffice is installed successfully type要检查 libreoffice 是否已成功安装,请键入
libreoffice --version
This should return the version number这应该返回版本号
Next install Microsoft fonts using接下来使用安装 Microsoft 字体
sudo apt install ttf-mscorefonts-installer
Also install any other font dependencies that you anticipate your documents could come with还安装您预计文档可能附带的任何其他字体依赖项
Finally use the below command to convert to pdf.最后使用以下命令转换为pdf。 Make sure no libreoffice application is running in the background确保没有 libreoffice 应用程序在后台运行
libreoffice --headless --invisible --convert-to pdf "test.docx" --outdir files
You should find the pdf in the folder called files您应该在名为 files 的文件夹中找到 pdf
This works on ubuntu 18.04.5 LTS.这适用于 ubuntu 18.04.5 LTS。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.