Bash 转 pdf

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4234164/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 22:56:34  来源:igfitidea点击:

Bash convert to pdf

bash

提问by danidacar

How can I use both ls and convert to transform all images files in a directory to a pdf ? Also I need to put the files in a certain order for example files like AA1.png,AA11.png need to respect this logical order.

如何同时使用 ls 和 convert 将目录中的所有图像文件转换为 pdf ?此外,我需要将文件按特定顺序排列,例如 AA1.png,AA11.png 之类的文件需要遵守此逻辑顺序。

Update (ls) and (convert) are available , but how can I used them together ?

更新 (ls) 和 (convert) 可用,但如何将它们一起使用?

回答by Orbling

To convert to a single PDF can be done in a single command:

要转换为单个 PDF 可以在单个命令中完成:

convert -compress jpeg *.jpg my-jpegs.pdf

Remember to include the -compress jpegflag, or it'll store the images uncompressed and result in a massive PDF.

请记住包含该-compress jpeg标志,否则它将存储未压缩的图像并生成大量 PDF。

ImageMagick (via convert) requires Ghostscript (gs) to be installed in order to process PDFs I believe. Beware of memory issues if you are adding a lot of JPEGs at once.

我相信 ImageMagick(通过转换)需要安装 Ghostscript(gs)才能处理 PDF。如果您一次添加大量 JPEG,请注意内存问题。

As for your logical ordering, you can use lsin combination with convertto get the list in order.

至于您的逻辑排序,您可以ls结合使用convert以按顺序获取列表。

Something along the lines of:

类似的东西:

convert -compress jpeg `ls *.png` my-jpegs.pdf

See ls --helpfor the various sorting options available.

有关ls --help可用的各种排序选项,请参阅。

回答by Robert Fleming

https://gitlab.mister-muffin.de/josch/img2pdf

https://gitlab.mister-muffin.de/josch/img2pdf

In all of the proposed solutions involving ImageMagick (i.e. convert), the JPEG data gets fully decoded and re-encoded. This results in generation loss, as well as performance "ten to hundred" times worse than img2pdf.

在所有涉及 ImageMagick(即convert)的建议解决方案中,JPEG 数据被完全解码和重新编码。这导致生成损失,以及比 img2pdf 差“十到一百”倍的性能。

回答by datnoobuser

If you have a lot of files:

如果你有很多文件:

convert -limit memory 1 -limit map 1 *.jpg foo.pdf

see here

看这里

or with compression

或压缩

convert -limit memory 1 -limit map 1 -compress jpeg -quality 85 *.jpg foo.pdf

回答by khachik

for image in `ls *.png`; do
  # call convert or whatever here
  convert $image `basename $image .png`.pdf
done