惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Microsoft Azure Blog
Microsoft Azure Blog
WordPress大学
WordPress大学
小众软件
小众软件
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
V
V2EX
Hugging Face - Blog
Hugging Face - Blog
美团技术团队
博客园 - 三生石上(FineUI控件)
Last Week in AI
Last Week in AI
酷 壳 – CoolShell
酷 壳 – CoolShell
博客园 - Franky
Microsoft Security Blog
Microsoft Security Blog
Y
Y Combinator Blog
A
About on SuperTechFans
The GitHub Blog
The GitHub Blog
U
Unit 42
H
Hackread – Cybersecurity News, Data Breaches, AI and More
云风的 BLOG
云风的 BLOG
IT之家
IT之家
MyScale Blog
MyScale Blog
V
Visual Studio Blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
I
InfoQ
博客园 - 司徒正美

jdhao's digital space

Conversion between base64 and OpenCV or PIL Image 腾讯云对象存储博客图床开启 CDN 加速(不需要购买额外域名) Search and Replace in Multiple Files in Vim/Neovim Change Table Column Width in LaTeX Image or Table Side by Side in LaTeX LaTeX 并排显示图像或表格 Firenvim: Neovim inside Your Browser Content inside HTML tags missing in Latest Hugo? Creating Markdown Front Matter with Ultisnips Labelme JSON 标注格式转 voc XML 格式 Nifty Nvim Techniques That Make My Life Easier -- Series 6 macOS 下如何为视频制作字幕 Running Command Asynchronously inside Neovim Resolving Merge Conflict after Git Stash Pop Pylint: command not found? A Hands-on Experience with Neovim's Built-in LSP Support How to Convert PDF to Images with Imagemagick 互联网上常用缩略语集锦 File Backup in Neovim Converting PDF Pages to Images with Poppler Nifty Nvim Techniques That Make My Life Easier -- Series 5 Neovim Configuration for System-wide Use How to sort a list of tuple or list in Python -- lambda or itemgetter? Building A Vim Statusline from Scratch 人类第一颗原子弹爆炸始末 Distributed Training in PyTorch with Horovod Learning Expect Programming Essential Knowledge about SSH Nifty LaTeX Techniques -- Series 1 更改 Adsense 邮寄地址,重新寄送 PIN
Convert PPTX Document to JPEG Images on Ubuntu
2020-03-30 · via jdhao's digital space
Changelog
  • 2020-12-24: Add how to convert pptx to pdf using unoconv.

In this post, I will share how to convert PPTX file to images. There are two steps. The first step is to convert PPTX to PDF, and the second step is to convert PDF to JPEG.

First, we need to install libreoffice:

apt update && apt install libreoffice

To install the latest version of libreoffice, run the following command instead:

# in order to use add-apt-repository command
apt install software-properties-common
apt-add-repository -y ppa:libreoffice/ppa
apt update && apt install libreoffice

Step one: from PPTX to PDF#

To convert PPTX to image, we need to first convert it to PDF

Use libreoffice directly#

We can use soffice provided by libreoffice to convert pptx to pdf directly:

soffice --headless --convert-to pdf test.pptx

This will create a file named test.pdf.

Use unoconv#

Apart from soffice, we can also use unoconv. Install the related packages first:

apt update && apt install python3-uno unoconv

Then use unoconv to convert pptx to pdf:

I met the following error when I run unoconv:

unoconv: Cannot find a suitable pyuno library and python binary combination in /usr/lib64/libreoffice
ERROR: Please locate this library and send your feedback to:
[http://github.com/dagwieers/unoconv/issues](https://github.com/dagwieers/unoconv/issues)
No module named uno
unoconv: Cannot find a suitable office installation on your system.
ERROR: Please locate your office installation and send your feedback to:
[http://github.com/dagwieers/unoconv/issues](https://github.com/dagwieers/unoconv/issues)

For me the error is because unoconv is using the wrong python. In fact, unoconv is just a python script with a shebang:

Since I also installed python3 via Anaconda and add it to the system path, the above shebang will actually use python3 from Anaconda, which is wrong.

The uno.py package is located in /usr/lib/python3/dist-packages/uno.py, and we need to use the system python3.

So we need to change the shebang of unoconv to:

According to comment here, we can also sed to do this:

sed -i 's|#!/usr/bin/env python3|#!/usr/bin/python3|' /usr/bin/unoconv

Step two: from PDF to image#

In order to turn PDF to images, we can use imagemagick or poppler.

With Imagemagick#

We need to install imagemagick:

Then we can convert PDF file to image using convert:

convert -density 150 test.pdf -quality 80 output-%3d.jpg

The -desnity option will control the dpi of generated image.

Possible issues#

During conversion, two errors occur after running the convert command:

convert-im6.q16: not authorized `multiple_img.pdf' @ error/constitute.c/ReadImage/412.
convert-im6.q16: no images defined `output-%3d.jpg' @ error/convert.c/ConvertImageCommand/3258.

For the first error, you can edit /etc/ImageMagick-6/policy.xml and change the following line:

<policy domain="coder" rights="none" pattern="PDF" />

to

<policy domain="coder" rights="read|write" pattern="PDF" />

For the second error, this is because ghostscript has not been installed on the system. Try to install it:

After that, you should be fine to generate from PPTX to jpg/png images.

With poppler#

We need to install poppler-utils:

apt-get update && apt-get install -y poppler-utils

For further steps, refer to this post.

References#