简体   繁体   English

如何在较新版本的 libreoffice 中使用 unoconv

[英]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:我要做的是:

  • first decrypt them temporarily in a separate folder首先在单独的文件夹中临时解密它们
  • use the unoconv command line to convert the decrypted file into pdf:使用 unoconv 命令行将解密后的文件转换为 pdf:

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.但它什么也不做。

  1. Is there a way to utilize unoconv with a LibreOffice version other than the 4.3?有没有办法在 4.3 以外的 LibreOffice 版本中使用 unoconv?

  2. 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.

相关问题 如何使用较新版本的libc? - How to use newer version libc? 当我使用的较新版本的库使用不同的函数名称时,如何解决硬编码? -蟒蛇 - How to resolve the hardcoding when a newer version of the library i use uses a different function name? - python 如何使用“venv”更新 Python 虚拟环境以使用更新版本的 Python? - How do I update a Python virtual environment with `venv` to use a newer version of Python? 如何让pip指向更新版本的Python - How to get pip to point to newer version of Python 如何为新的python版本安装numpy - how to install numpy for newer python version 我安装了 2 个版本的 python,但 cmake 使用的是旧版本。 如何强制 cmake 使用较新版本? - I have 2 versions of python installed, but cmake is using older version. How do I force cmake to use the newer version? 如何将 LibreOffice API (UNO) 与 Python + Windows 一起使用? - How to use LibreOffice API (UNO) with Python + Windows? 如何将 python 软件包从旧版本安装到新版本? - How to install python packages from older version to newer version? 在 AWS Lambda 上安装更新版本的 sqlite3 以与 Python 一起使用 - Install newer version of sqlite3 on AWS Lambda for use with Python 如何通过 django python 中的子进程运行 unoconv? - How to run unoconv via subprocess in django python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM