批量将PNG转换为单个PDF,同时保持bash中的深层文件夹层次 [英] Batch convert PNGs to individual PDFs while maintaining deep folder hierarchy in bash

查看:114
本文介绍了批量将PNG转换为单个PDF,同时保持bash中的深层文件夹层次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我找到了一个声称可以做一个文件夹的解决方案,但是我有一个很深的活页乐谱文件夹层次结构,我想将其从png批量转换为pdf.我的解决方案是什么样的?

I've found a solution that claims to do one folder, but I have a deep folder hierarchy of sheet music that I'd like to batch convert from png to pdf. What do my solutions look like?

我会遇到进一步的问题,这可能会使事情复杂化.也许我应该写一个脚本? (我总共是n00b fyi)

I will run into a further problem down the line, which may complicate things. Maybe I should write a script? (I'm a total n00b fyi)

进一步的问题"是我的某些乐谱跨越了一页以上,因此,如果脚本可以将包含"1of2"和"2of2"的文件名解析为单个pdf,那将是整齐的

The "further problem" is that some of my sheet music spans more than one page, so if the script can parse filenames that include "1of2" and "2of2" to be turned into a single pdf, that'd be neat.

我在这里有什么选择?

非常感谢您.

推荐答案

更新后的答案

作为替代方案,以下操作应该更快(因为它可以并行进行转换),并且还可以处理大量文件:

As an alternative, the following should be faster (as it does the conversions in parallel) and also able to handle larger numbers of files:

find . -name \*.png -print0 | parallel -0 convert {} {.}.pdf

它使用 GNU Parallel (在Linux/Unix上很容易获得),并且可以使用homebrew通过以下方式简单地安装在OSX上:

It uses GNU Parallel which is readily available on Linux/Unix and which can be simply installed on OSX with homebrew using:

brew install parallel

原始答案(接受)

如果您具有bash版本4或更高版本,则可以使用extended globbing递归目录并非常简单地完成工作:

If you have bash version 4 or better, you can use extended globbing to recurse directories and do your job very simply:

首先通过以下方式启用extended globbing:

First enable extended globbing with:

shopt -s globstar

然后将PNG递归转换为PDF:

Then recursively convert PNGs to PDFs:

mogrify -format pdf **/*.png

这篇关于批量将PNG转换为单个PDF,同时保持bash中的深层文件夹层次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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