Resize Images and save them to a PDF

I have a client who has many jpg images in many folders. All folders are sub-folders of one main folder.
For every folder, I want to create a PDF file of all the images in that folder. I want the PDF file to be small so I'd like every image to be resized down to 240 pixels wide. I'd like to have multiple images on each page so they are easy to browse and I need the image file name to be shown below each image.
I need to be able to run a script periodically (via task scheduler) to automatically recreate the PDF if any image files have been added to, deleted from or changed in any folder.
Is there any software or combination of programs which I can achieve this with? This needs to be fully automated so it can happen without human intervention.
LVL 13
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

EirmanChief Operations ManagerCommented:
You want to create a thumbnail gallery of multiple JPGs in multiple folders.
Is it really important to your client that the output is in PDF format?
Would an output in JPG format suffice?
akbAuthor Commented:
JPG may suffice.
EirmanChief Operations ManagerCommented:
I just realised that you wish to create Contact Sheets of your images,
so use that term when searching for suitable software.

This is a nice piece of portable freeware that will do the job for a folder AND all sub-folders.
There is no spyware. (I've used their excellent FlashRenamer program for years).
I can't help you with the automation.
Click on the "! Request Attention" and ask a moderator to add suitable scripting topics/zones.
(Or just create another question for the scripting aspect of things)

AutoHotKey might be all you need
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Joe Winograd, Fellow&MVEDeveloperCommented:
The Snap2IMG utility that Eirman posted is an excellent (and free!) tool. However, it does not support a command line call (except for specifying the root folder), so automation with it would rely on a scripting language like AutoHotkey, as Eirman noted.

However, I'm working on a different approach using another excellent tool (also free!) called GraphicsMagick, which is a command line product. This EE article explains how to download and install it:
Reduce the file size of many JPG files in many folders via an automated, mass, batch compression method

GraphicsMagick can create a multi-page PDF or TIFF file with thumbnails of all the JPGs in a folder, including the file name under each thumbnail. It calls this a Montage (the same as what Snap2IMG calls a Contact Sheet).

I'm working on a program that will do this in a completely automated/unattended manner, and plan to write an article about it as soon as I complete it (probably in a day or two). Will post back here as soon as I have a link to the article. Regards, Joe

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Joe Winograd, Fellow&MVEDeveloperCommented:
Hi akb,

I just submitted the article for publication. The new Articles system allows you to share an article before it is published, so here's the link for you:
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

I had actually started the project by writing an AutoHotkey program, which is working, and is more robust than the batch file approach in the article, as it does substantial error checking, has the ability to create a TIFF file instead of PDF (or both), and can call IrfanView to convert from TIFF to PDF (rather than using GraphicsMagick for it — there are pros and cons). But it's around 100 lines of code and in the end I decided the simplicity of a 9-line batch file without the need for another product was the way to go. I may continue to tweak the AutoHotkey version and publish it someday, but for now I hope you find that the simple solution in the article works well for your purposes — but if not, let me know.

You'll still need to download and install GraphicsMagick, as described in my previous article:
Reduce the file size of many JPG files in many folders via an automated, mass, batch compression method

Regards, Joe
akbAuthor Commented:
Thanks Joe. I will check this out in the morning.
Excellent work Joe.  I actually created a solution using ImageMagick and the same modifiers and operators when I realised that I was writing what would amount to a tutorial.  I always find it a difficult balance between providing a working solution (i.e. just the batch file) without any explanation how the process works, and posting too much explanation.  Sometimes the asker wants to know how it works and sometimes not.  I was editing it down but I needed to sleep and I had a funny feeling that somebody like you would have posted a command line solution before I woke up again.
Joe Winograd, Fellow&MVEDeveloperCommented:
Hi Bill,
Thanks for the compliment — I appreciate hearing it! Interesting that you went the ImageMagick route. As I'm sure you know, GraphicsMagick is a fork of ImageMagick (in 2002, and has been independent of ImageMagick ever since). Both products have improved since then, but the core features remain very similar, and I'm sure you can achieve the same results with ImageMagick as I did with GraphicsMagick (although I'm not familiar with ImageMagick's support for PDF). Regards, Joe
I've never used ImageMagick for PDF output.  As far as I recall there were some "issues" with PDF output, but they were probably resolved in later revisions of the software from the time that I read about the bugs or quirks.  I have used ImageMagick's MONTAGE command to create thumbnail web pages by simply choosing HTML as the alternative output to standard image format, TIFF, or PDF.  It works fine for that, but I prefer using a modified IrfanView *.INI template file to quickly generate thumbnail web pages.

On the subject of PDF, I still cannot really understand the asker's client's need for one or more pages or images of thumbnails in each folder:
"I'd like to have multiple images on each page so they are easy to browse".

As far as I am concerned Windows Explorer in thumbnail view or slideshow view provides the easiest and best medium to browse images, which can then be quickly and easily opened to full size using the built-in viewer.  The alternative is one of the many free image viewers and editors that provide a right-click menu option on folders to open the (filtered) contents of a folder in thumbnail view, and most of them allow you to configure the size and layout of the thumbnails and to display the "Explorer-type" folder tree down the side for navigation.

A PDF file or "index print" image is only really useful after it is opened maximised in a PDF or image viewer anyway.  It doesn't provide a clickable means to open any of the thumbnails, so it all seems nonsensical to me.  Nevertheless you have addressed the asker's requirements fully.
Joe Winograd, Fellow&MVEDeveloperCommented:
> As far as I am concerned Windows Explorer in thumbnail view or slideshow view provides the easiest and best medium to browse images, which can then be quickly and easily opened to full size using the built-in viewer.

You make a good point, Bill, but the ability of users varies dramatically. I was on an EE thread where the asker said something like, "Oh, no, not that dreaded Windows Explorer thing." So for some folks, as strange as this sounds to the Experts, using the fancier aspects of Windows/File Explorer (such as changing the view or showing the preview pane) may be beyond reach. But it's pretty fair to say that nearly everyone who uses a computer these days knows how to pull up a PDF file in Adobe Reader (or whatever PDF reader/viewer they have). So using their PDF reader's browse/navigate feature to find the contact sheet for a folder may be a better solution for some users — and when they see the thumbnail that interests them, they can use Windows/File Explorer with its standard settings to find the file (since its file name is under the thumbnail) and simply double-click on it — or, alternatively, run whatever program they use to view JPGs, such as MS Office Picture Manager, and browse/navigate to the file. Of course, if you have Picture Manager, you already have a contact sheet — click the Thumbnail View button — maybe a better example is MS Paint. :)

> Nevertheless you have addressed the asker's requirements fully.

Thanks for that!

Regards, Joe
Joe Winograd, Fellow&MVEDeveloperCommented:

I've been doing some thinking on this issue since my last post, and am coming down on your point of view. Even if akb's client can't handle Windows/File Explorer, there are other solutions which can likely be taught in a few minutes, such as IrfanView, with its Thumbnails feature. For example, by running IrfanView and clicking File>Thumbnails (or simply the "T" key, which is the shortcut for it), it brings up a page like this (this is the same folder that I used in my article):

IrfanView Thumbnails
Each thumbnail has the name of the image underneath it, and double-clicking on the thumbnail brings it up full-size in the main IrfanView window. Furthermore, you can use the left and right arrow keys (or click those icons on the toolbar) in the main window to browse through all of the images in a folder, and you can use the navigation panel in the thumbnails window to go to any folder/subfolder. In addition, the thumbnails get dynamically generated and can be refreshed via View>Refresh all (or the F5 shortcut key), so there's no need for periodically running a Task Scheduler refresh job.

So I'm now wondering about the purpose of the PDF file with the contact sheets in each subfolder. I hope that akb will jump in and explain the reason to us after the sun rises down under. :)

Regards, Joe
akbAuthor Commented:

It is 7:48am here in Tasmania, Australia so my replies may be a bit slow due to the time zone difference.

The reason for the PDF's is that my client is using OneDrive to store documents for his staff to access while they are one the road, at a customer's site or from home. The JPG's change daily - mostly added to. They don't want to be loading full sized images up to OneDrive as they are too big and their internet connection is quite slow. They can't upload all their images anyway because of Microsoft's limitation of 20,000 files in a OneDrive library.

They need to be able to access contacts and other documents while off site. They also need to be able to look at thumb nails of the images so they can select images to go into brochures and advertisements by file name. Thumb nails are sufficient for this purpose as they have access to the full sized images elsewhere on the internet but those images don't have the file names associated with them - the file names are changed by the web site which publishes them.

By uploading PDF's of the images/file names, they can browse the thumbnails while off-site from a laptop, their home PC, their iPads/iPhones and their android devices - there are about 20 staff who need to do this.

Thanks again for all your help and I will give you feedback when I have had a chance to set this up.

Joe Winograd, Fellow&MVEDeveloperCommented:
Hi Andrew,
Thanks for explaining — I think I get it now. When your initial post said that you want a PDF file of all the images in each folder, I thought you'd be storing each PDF in the same folder with its JPGs. But, if I'm understanding you right this time, I think you want to store all of the PDFs elsewhere — in fact, uploaded to OneDrive. So this means either (1) each PDF should have a different file name, perhaps with the original path embedded in the file name, maybe replacing colons and backslashes with a character that doesn't appear in their folder names, such as an underscore (for example, Montage C_root folder_subfolder 1.pdf) or (2) OneDrive should replicate the folder/subfolder structure where the JPGs are located so that the montage PDF files with the same name (such as Montage.pdf) are stored in each OneDrive folder with the same name as the corresponding folder where the JPGs are. Which is it? Or is there another way that I'm missing? Regards, Joe
akbAuthor Commented:
Hi Joe,
Number 2 is the one. There are contracts, JPGs and other documents stored in several hundred folders on the server. The folders are well structured. The idea is that the PDFs will be created in the same folders as the JPGs. I then use FreeFileSync to create a mirror of this folder structure to the OneDrive folder for upload to OneDrive along with the other documents but the JPGs are filtered out from the FreeFileSync mirror.
The reason for the FreeFileSync mirror is that we are finding OneDrive to be a bit unreliable. Sometimes we need to delete the whole lot and resync it again. Sometimes OneDrive puts back folders and files that were deleted on the server. We need to use OneDrive as the client is using Office 365 for Outlook and Word Online and OneDrive makes it easy for them to access and edit their documents.
I am unable to test your solution at the moment as the customer is having software installed on their server by another organisation.
The only potential issue I see is that I don't want all the PDFs being recreated each time the script is run. I only want new PDFs created if JPGs have been added, deleted or changed in a folder and then I only want that PDF to be recreated.
I may need to write a small program to control this.
Joe Winograd, Fellow&MVEDeveloperCommented:
Thanks for the additional explanation — very helpful! This is probably where I'd switch gears away from a batch file script to a "real" program in my programming language of choice (these days, AutoHotkey). The program would retrieve the (Modified) date/time stamp of the montage PDF file (MontageDate) and compare it to the (Modified) date/time stamp of the newest JPG in the folder (NewestDateJPG). It would execute the gm.exe call only if NewestDateJPG is later than MontageDate. It may be possible to incorporate this into the batch file posted in my article, but I suspect it will be a lot easier in an AutoHotkey program (or in any other robust programming language). Of course, if you feel that you can control that aspect of the solution with a small program (as mentioned in the last sentence of your previous post), that's a great way to go. Regards, Joe
akbAuthor Commented:
Hi Joe,
It's not as simple as looking for newer files. The images come from several sources and could be several days old before they are loaded to the server. I think I will need a program to keep track of each image in each folder and rerun the script if there are any changes.
I'm thinking about putting a hidden file into each folder (so the users don't see them) which contains file names and date/time modified for each JPG currently in the folder. Every so often task scheduler will call my program which will run through all the folders looking for new/deleted/modified JPGs. If it finds one then it will call your solution to create a new PDF for that folder and update the hidden file.
Joe Winograd, Fellow&MVEDeveloperCommented:
Hi Andrew,
That's an interesting idea to keep track of each JPG and put a hidden file in each folder. Brilliant! Regards, Joe
Joe Winograd, Fellow&MVEDeveloperCommented:
A quick note to let you know that I updated the GraphicsMagick command line call in my article to include the -compress option with JPEG compression. This results in significantly smaller PDFs, which should be very helpful for your particular usage of the solution. Here are some test results:

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%

Open in new window

This will make it much faster to upload the PDFs to OneDrive.

Also, I'm looking into your idea of tracking all JPGs via a hidden file in each folder, but that would be in the AutoHotkey program, not the batch file script. Regards, Joe
Thank you for all the in-depth feedback.  As Joe says, it really does clarify the requirements and allows the solution to be fine tuned to suit.
akbAuthor Commented:
A quick update. I have been busy with other more pressing matters but will get back on to this in the next day or so. Thanks for your patience.
Joe Winograd, Fellow&MVEDeveloperCommented:
No rush on this end. Regards, Joe
akbAuthor Commented:
I know it has been a long time since this question was asked. I have been taken away from it by more urgent matters. I will definitely be returning to it soon. Thanks for your patience.
Joe Winograd, Fellow&MVEDeveloperCommented:
Thanks for the update...still no rush here.
akbAuthor Commented:
Even though I haven't got back to this project yet I am accepting Joe's answer as it will work. Thanks for all you r assistance. I will get back to you about your proposal when I return to this project.
Joe Winograd, Fellow&MVEDeveloperCommented:
Hi Andrew,
Thanks for closing the question and accepting my answer — I appreciate it! I've made some further progress on the AutoHotkey version and very much look forward to hearing back from you on my proposal when you return to this project. Regards, Joe
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Images and Photos

From novice to tech pro — start learning today.