批量撤销文件夹下工作表保护_使用自动批量方法为文件夹及其每个子文件夹中的所有JPG文件创建带有联系表(缩略图的蒙太奇)的PDF文件

批量撤销文件夹下工作表保护

This article provides the solution to a

本文提供了一种解决方案

question

posed here at Experts Exchange. The asker of the question has many JPG images in many folders, and all of the folders are subfolders of one root folder. For each folder, the asker wants to create a PDF file containing thumbnail images (sized to 240 pixels wide) of every JPG in that folder. This is commonly known as a contact sheet or montage.

在Experts Exchange上摆出的姿势 该问题的询问者的许多文件夹中都有许多JPG图像,并且所有文件夹都是一个根文件夹的子文件夹。 对于每个文件夹,请求者都希望创建一个PDF文件,其中包含该文件夹中每个JPG的缩略图(大小为240像素宽)。 这通常称为联系表蒙太奇

Let's begin the article with an illustration showing the results of this solution. Here's a Windows/File Explorer screenshot displaying a folder with four JPGs, which were the input files in a test run, and a single PDF, which was the resulting output file from the test run:

让我们从展示该解决方案结果的插图开始。 这是Windows / File Explorer的屏幕快照,其中显示了一个文件夹,其中包含四个JPG(是测试运行中的输入文件)和一个PDF(是测试运行中的输出文件):

Create-Montage-PDF-from-JPGs.jpg

In that test run, all of the JPGs in the folder fit well on a single page in the output PDF file. But if there are too many images to fit on one page, the asker wants the resulting file to be a multi-page PDF. Also, the file name of each JPG should be shown below its thumbnail. All of this needs to be accomplished with a fully automated, unattended method, capable of being run by the Task Scheduler without user intervention.

在该测试运行中,文件夹中的所有JPG都非常适合输出PDF文件中的单个页面。 但是,如果一页上的图像太多,则询问者希望生成的文件为多页PDF。 另外,每个JPG的文件名应显示在其缩略图下方。 所有这些都需要使用一种全自动,无人值守的方法来完成,该方法能够由Task Scheduler运行而无需用户干预。

One of the experts (Eirman) participating in that question recommended a terrific (and free!) utility (Snap2IMG) that can produce such contact sheets, but as a JPG file, not a PDF. Also, the utility presents a GUI, which (Eirman noted) could likely be automated with a scripting language like AutoHotkey, but it does not support command line calls (except to provide the root folder).

参与该问题的一位专家( Eirman )推荐了一个很棒的(免费的!)实用程序( Snap2IMG ),它可以生成这种联系表,但可以生成JPG文件,而不是PDF。 此外,该实用程序还提供了一个GUI ,(可能有Eirman指出)可以使用诸如AutoHotkey之类的脚本语言来自动化该GUI ,但它不支持命令行调用(提供根文件夹除外)。

So I decided to take the approach of using a product that was designed to be run from the command line, making it more amenable to an automated, batch file solution. The product is the excellent (and free!) GraphicsMagick. I've already published an article at EE which explains how to download and install GraphicsMagick, so rather than repeating those instructions here, I refer you to that article:

因此,我决定采用一种设计为从命令行运行的产品的方法,从而使其更适合于自动化的批处理文件解决方案。 该产品是出色的(免费!) GraphicsMagick 。 我已经在EE上发表过一篇文章,其中介绍了如何下载和安装GraphicsMagick,因此,在这里不再重复这些说明,而是将您引向该文章:

Reduce the file size of many JPG files in many folders via an automated, mass, batch compression method 通过自动批量批量压缩方法减少许多文件夹中许多JPG文件的文件大小

After installing GraphicsMagick using the instructions in that article, the next step is to write the batch file that makes the appropriate command line call in order to create the multi-page PDF file with the thumbnail images — what GraphicsMagick calls a montage. Borrowing some from my previous article, here's the batch file that accomplishes the task:

使用该文章中的说明安装GraphicsMagick之后,下一步是编写批处理文件,以进行适当的命令行调用,以创建带有缩略图的多页PDF文件-GraphicsMagick称为montage 。 借用我上一篇文章中的一些内容,这是完成任务的批处理文件:

SET RootFolder="c:\root folder"
SET OutputFile="Montage.pdf"
SET ThumbnailPixelSize="240x320+4+8>"
SET FilenameFontSize=12
SET ColumnsByRows=4x5
FOR /R %RootFolder% %%G in (.) DO (
  PUSHD %%G
  gm.exe montage -compress JPEG -font Arial -pointsize %FilenameFontSize% -tile %ColumnsByRows% -frame 6 -shadow -label %%t -geometry %ThumbnailPixelSize% *.jpg %OutputFile%
  POPD )

Simply copy those nine lines of code into a batch (.BAT) file and schedule it via Task Scheduler (or, of course, run it manually or put it in the Startup program group). Notes: (1) There is no error check on the value of RootFolder — make sure it is valid and exists. (2) If a folder has no JPG files in it, the call to gm.exe will fail, but the batch file will continue to run fine (recursing into all subfolders), allowing for unattended operation with no user intervention. (3) This solution will overwrite an existing output (montage) PDF file with no warning.

只需将这九行代码复制到批处理( .BAT )文件中,然后通过Task Scheduler对其进行调度 (当然,也可以手动运行它或将其放在Startup程序组中)。 gm.exe的调用将失败,但是批处理文件将继续正常运行(递归到所有子文件夹),从而允许无人参与的操作而无需用户干预。 (3)此解决方案将覆盖现有的输出(蒙太奇)PDF文件,而不会发出警告。

I created local variable names in the batch file that are largely self-documenting and should make it easy for anyone using this solution to configure the parameters: the root folder, the name of the output (montage) PDF file, the size in pixels of each thumbnail (and the spacing), the font size to use for the file name that is placed under each thumbnail, and the number of columns and rows of thumbnails appearing on each page of the PDF file.

我在批处理文件中创建了局部变量名,这些变量在很大程度上是自我记录的,使用此解决方案的任何人都应该可以轻松配置参数:根文件夹,输出(蒙太奇)PDF文件的名称,像素大小每个缩略图(和间距),用于放置在每个缩略图下方的文件名的字体大小,以及出现在PDF文件每一页上的缩略图的列数和行数。

One variable that deserves some explanation is ThumbnailPixelSize. The four values (in pixels) are width of thumbnail, height of thumbnail, horizontal spacing between thumbnails, and vertical spacing between thumbnails (note: the greater-than sign at the end of the four values is important — be careful to leave it if you change values). Thus, the initial value in the code above means that each thumbnail will be sized to 240 pixels wide and 320 pixels high (but the aspect ratio is maintained), while there will be four pixels between each column of thumbnails and eight pixels between each row of thumbnails. Here's what a montage of them looks like:

一个值得解释的变量是ThumbnailPixelSize 。 四个值(以像素为单位)分别是缩略图的宽度,缩略图的高度,缩略图之间的水平间距和缩略图之间的垂直间距( 注意:这四个值末尾的大于号很重要-请小心放置,如果您更改值)。 因此,上述代码中的初始值意味着每个缩略图的大小将分别为240像素宽和320像素高(但保​​持宽高比),而缩略图的每一列之间将有四个像素,而每行之间将有八个像素的缩略图。 这是其中的蒙太奇画面:

Montage-PDF-page-240-320-4-8-shadow.jpg

That's a screenshot of a page from the PDF file created by this solution. The run that created it used the ThumbnailPixelSize parameter shown in the code posted above, that is, "240x320+4+8>", and with the -shadow option (discussed below). Likewise, here's a screenshot from a run against the same folder with the same set of JPGs, but with the ThumbnailPixelSize parameter set to "240x240+0+0>", and without the -shadow option:

这是此解决方案创建的PDF文件中的页面的屏幕截图。 创建它的运行使用了上面代码中显示的ThumbnailPixelSize参数,即“ 240x320 + 4 + 8> ”,并带有-shadow选项(如下所述)。 同样,这是在具有相同JPG集但具有ThumbnailPixelSize参数设置为“ 240x240 + 0 + 0> ”且没有-shadow选项的情况下针对同一文件夹运行的屏幕截图:

Montage-PDF-page-240-240-0-0-no-shadow.j

The quality of the actual PDF files is better than the screenshots shown above, and I have attached the two-page PDF from each run to corroborate that (the subfolder for this particular montage has 40 JPGs in it, so the 4-column by 5-row run created a two-page PDF).

实际PDF文件的质量比上面显示的屏幕截图要好,我在每次运行中都附上了两页的PDF,以证实这一点(此特定剪辑画面的子文件夹中有40个JPG,因此4列乘5行创建了两页PDF)。

In addition to the parameters discussed above, I chose some other parameters for the GraphicsMagick call: compress the PDF file with JPEG compression, the font of Arial, a frame of six pixels (surrounds each thumbnail with an ornamental border), and a shadow (adds a nice visual effect to each thumbnail). The JPEG compression results in a significant reduction in the size of the PDF file. Here are some test results:

除了上面讨论的参数,我选择为GraphicsMagick工具呼叫一些其它参数: 压缩 PDF文件以JPEG压缩,Arial字体的字体 ,六个像素的 (与周围的装饰性边界每个缩略图),和一个影子 (为每个缩略图添加漂亮的视觉效果)。 JPEG压缩可显着减小PDF文件的大小。 以下是一些测试结果:

PDF size in bytes without     PDF size in bytes with the     Compression
  the -compress option       -compress option set to JPEG       Ratio

          38,507                        16,595                   57%
         741,142                       208,090                   72%
         916,381                       272,355                   70%
       1,556,917                       307,080                   80%
       2,931,450                       616,611                   79%
       5,255,587                     1,235,601                   76%

There are many other options available in the montage sub-command — enjoy experimenting with them!

蒙太奇子命令中还有许多其他选项可用,请尝试一下!

If you find this article to be helpful, please click the thumbs-up icon below. This lets me know what is valuable for EE members and provides direction for future articles. Thanks very much! Regards, Joe

如果您发现本文有帮助,请单击下面的大拇指图标。 这使我知道什么对EE成员有价值,并为以后的文章提供了指导。 非常感谢! 问候乔

Montage-240-320-4-8-shadow.pdf 蒙太奇240-320-4-8-shadow.pdf Montage-240-240-0-0-no-shadow.pdf Montage-240-240-0-0-no-shadow.pdf

翻译自: https://www.experts-exchange.com/articles/18414/Create-a-PDF-file-with-Contact-Sheets-montage-of-thumbnails-for-all-JPG-files-in-a-folder-and-each-of-its-subfolders-using-an-automated-batch-method.html

批量撤销文件夹下工作表保护

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值