pdf转img

默认分类 · 05-31

使用linux的一大好处就是可以有各种软件,免费而方便实现各类功能,今天就来讲讲怎样实现pdf转img。

1.系统背景

  • 操作系统:debian 12

2.pdf转img

2.1 软件名称

  • pdftoppm

2.2 软件安装

  • 打开终端,输入如下内容

sudo apt install poppler-utils

2.3 软件使用

  • test.pdf文件:打开终端,输入下面内容,最后得到图片test-1.pngtest-2.png,其中1、2是pdf文件的页码。

pdftoppm test.pdf test -png
  • 如果要用python批量转换/tmp/test/目录下的所有pdf文件,整个代码如下:

#!/usr/bin/python3

import os

os.chdir('/tmp/test/')

hehe = os.popen('ls').readlines()

for pdf in hehe:

pdf = pdf.rstrip('\n')

print(pdf)

os.system(f'pdftoppm {pdf} {pdf} -png')
pdf
Theme Jasmine by Kent Liao