如何在Bash中将所有png文件转换为pdf?

编程入门 行业动态 更新时间:2024-10-28 04:21:57
本文介绍了如何在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?

本文发布于:2023-07-27 02:42:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219890.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:转换为   中将   文件   如何在   png

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!