我基本上是使用wget从网站下载一些图像,然后使用命令行程序“convert”将它们附加到PDF文件中。 但最后这件事似乎不起作用。
我正在获取所有.jpg图像并将它们存储到一个文件夹中没有任何问题,但是当我尝试将它们合并到PDF文件中时,它总是提醒最后添加的图像。 我已经阅读了convert的-append参数,但它仍然无效。
这就是我的代码的样子:
for file in *.jpg do convert "${file}" -append "myfile.pdf" done但是看起来很合乎逻辑, myfile.pdf总是最后只有最后一个jpg附加图像。 我知道使用转换像:
convert img1.jpg img2.jpg img3.jpg myfile.pdf会做的伎俩。 但由于我不知道下载目录中有多少图像,我无法对参数进行硬编码,所以我想在我尝试的目录中为每个图像设置一个循环是最好的解决方案。
有人知道如何实现我的目标吗? 任何帮助都感激不尽。
提前致谢。
I'm basically downloading some images from a website using wget to then append them into a PDF file using the command line program "convert". But this last thing seems not to work.
I'm getting all the .jpg images and storing them into one folder with no problems, but when I try to merge them into the PDF file, it always reminds with the last appended image. I've read of the convert's -append argument, but it still won't work.
This is how my code looks like:
for file in *.jpg do convert "${file}" -append "myfile.pdf" doneBut as logical as it seems, myfile.pdf always ends up having only the last jpg appended image. I know that using convert like:
convert img1.jpg img2.jpg img3.jpg myfile.pdfWould do the trick. But as I don't know how many images will I have in the download directory, I cannot hardcode the arguments, so I guess a loop for each image in that directory as I'm trying would be the best solution.
Does anybody know how to achieve my goal? Any help will be much appreciated.
Thanks in advance.
最满意答案
bash自动扩展通配符参数(除非它们被引用或转义),所以即使convert不支持通配符扩展, bash也可以。 所以你可以做到
convert *.jpg myfile.pdf请注意,如果文件太多,可能会导致“arglist太长”。 但是对于几百个文件来说应该没问题。
bash automatically expands wildcard arguments (unless if they are quoted or escaped) so even if convert does not support wildcard expansion, bash does. So you could just do
convert *.jpg myfile.pdfnote that if there are too many files, this can result with "arglist too long". But that should be OK for several hundred files.
更多推荐
发布评论