如何在Bash中将所有png文件转换为pdf? [英] How to convert all png files to pdf in Bash?

查看:67
本文介绍了如何在Bash中将所有png文件转换为pdf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

for f in find *.png; do convert "$f" "$f".pdf; done

这是我必须在目录中找到png文件并将其转换为pdf的方法,但是我遇到了错误.在Bash中执行此操作的更好方法是什么?

This is what I have to find the png files in the directory and convert them to pdf, but I get errors. What is a better way to do this in Bash?

convert: unable to open image `find': No such file or directory @ error/blob.c/OpenBlob/2705.
convert: no decode delegate for this image format `' @ error/constitute.c/ReadImage/504.
convert: no images defined `find.pdf' @ error/convert.c/ConvertImageCommand/3257.

推荐答案

for 循环提供的文件名列表实际上包含 find .我认为您要执行的操作是提供 find output ,搜索当前目录中或该目录下的所有PNG图片.

The list of filenames you are giving to the for loop literally contains find. I think what you meant to do is give the output of find, searching for all PNG images in or under the current directory, which is

for f in $(find . -iname '*.png'); do convert "$f" "$f".pdf; done

这将不能很好地处理空格.更好的解决方案是只在 find 本身内部运行转换,

This will not handle spaces well. A better solution is to just run the conversion from within find itself,

find "$PWD" -iname '*.png' -execdir convert '{}' '{}'.pdf \;

尽管请注意,最后将使用以 .png.pdf

Although note that you will wind up with filenames ending with .png.pdf

这篇关于如何在Bash中将所有png文件转换为pdf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆