将压缩的 JPG 转换为 PDF

Convert zipped JPGs into PDFs

我有一个包含很多 ZIP 文件的文件夹。每一个都包含文档的扫描页面,我需要将其转换为 PDFx.zipy.zip的结果需要是x.pdf 和 y.pdf.

我阅读 this thread 并看到 convert -compress Zip *.jpg output.pdf 将 JPG 转换为单个 PDF,但我的是压缩的。 是否有 Linux (Ubuntu 15.10) 的单行命令可用于对所有文件完成此操作?

谢谢。

您可以使用 unzip 实用程序解压缩存档,然后使用 convert 命令引用它们。这是一个被骗的 one liner(两个命令),但它有效:

unzip \*.zip; convert -compress Zip *.jpg output.pdf

这会将您的所有文件解压缩到当前目录,然后加载所有 .jpg 扩展文件并将它们放在名为 output.pdf

的单个 PDF 中的单独页面上

我在 Python 做了一个。不是最好的方法,但有效。我需要类似的东西,但更简单、更快。

from os import listdir, system, getcwd
from os.path import isfile, join
mypath = getcwd()
onlyfiles = [f for f in listdir(mypath) if isfile(join(mypath, f))]

system('mkdir tmp')

for f in onlyfiles:
    g = f.split('.')[0]
    system('rm tmp/*')
    system('unzip "%s" -d tmp' % f)
    system('convert tmp/* "%s.pdf"' % g)

system('rm -rf tmp')