Converting Multiple Images into a PDF File

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
cageybee
Posts: 5
Joined: 2017-03-21T15:16:49-07:00
Authentication code: 1151

Converting Multiple Images into a PDF File

Post by cageybee »

Hi,

I have a folder with a bunch of images in it. Some images have a particular string in the filename, like "mhk". I need to grab only those images from that folder and put them into a PDF file, with each image having its own page.

I tried different things but I can't even get past just combining them into a single image, let alone into a PDF.

Here is what I have:

Code: Select all

magick montage `dir /b | findstr mhk` -mode concatenate -tile 1x out.png
Somebody please help.

Thanks,

Ramin
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting Multiple Images into a PDF File

Post by snibgo »

You say you want the PDF "with each image having its own page".

Then you say "I can't even get past just combining them into a single image".

Which of these do you want? A PDF with a single page, with a single image that is a combination of all the input images? Then:

Code: Select all

magick montage *mhk* -mode concatenate -tile 1x out.pdf
Or do you want a PDF with as many pages as there are input images, one image per page? Then:

Code: Select all

magick *mhk* out.pdf
snibgo's IM pages: im.snibgo.com
cageybee
Posts: 5
Joined: 2017-03-21T15:16:49-07:00
Authentication code: 1151

Re: Converting Multiple Images into a PDF File

Post by cageybee »

snibgo wrote: 2017-03-21T16:03:50-07:00 You say you want the PDF "with each image having its own page".

Then you say "I can't even get past just combining them into a single image".

Which of these do you want? A PDF with a single page, with a single image that is a combination of all the input images? Then:

Code: Select all

magick montage *mhk* -mode concatenate -tile 1x out.pdf
Or do you want a PDF with as many pages as there are input images, one image per page? Then:

Code: Select all

magick *mhk* out.pdf
Thank you very much! I wanted the second one but the first one I will save for future use. Thanks a million!
cageybee
Posts: 5
Joined: 2017-03-21T15:16:49-07:00
Authentication code: 1151

Re: Converting Multiple Images into a PDF File

Post by cageybee »

snibgo,

I have a second question for you, if I may. How about this scenario:

I have several banners: Page1.png, Page2.png, ... Page10.png, and I have lots of images but they are in groups. Each group is identified with a special alphanumeric code, like "mhk" so, it looks like this:

image1mhk.png
image2mhk.png
...
image10mhk.png

image11xyz.png
image12xyz.png
...
image20xyz.png

...

And the group number varies. The group list can be in a text file like so:

mhk
xyz
...

I need to montage the banner with the image and then put it into its own PDF page. So, it will look like this.

=====Page 1 of PDF=====
Page1.png
image1mhk.png

=====Page 2 of PDF=====
Page2.png
image2mhk.png

...

=====Page 11 of PDF=====
Page1.png
image11.xyz.png

=====Page 12 of PDF=====
Page2.png
image12xyz.png

...

I would greatly appreciate your help.

Sorry, I am new to ImageMagick and I love it but I don't know much about it and I need to know a lot about it :)
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting Multiple Images into a PDF File

Post by snibgo »

What's the problem? From your OP, you know how to montage two files together, to make a third. You can do that many times (or in a shell loop) to montage each Page*.png file with a image*xyz.png file.

Then you can take each result, making a PDF with one page per result, as I showed you:

Code: Select all

magick result*.png out.pdf
I suggest you use leading zeroes in your numbering scheme, so they come out in the order you expect, eg result001.png, result002.png, ... result010.png.
snibgo's IM pages: im.snibgo.com
cageybee
Posts: 5
Joined: 2017-03-21T15:16:49-07:00
Authentication code: 1151

Re: Converting Multiple Images into a PDF File

Post by cageybee »

snibgo wrote: 2017-03-22T08:31:21-07:00 What's the problem? From your OP, you know how to montage two files together, to make a third. You can do that many times (or in a shell loop) to montage each Page*.png file with a image*xyz.png file.

Then you can take each result, making a PDF with one page per result, as I showed you:

Code: Select all

magick result*.png out.pdf
I suggest you use leading zeroes in your numbering scheme, so they come out in the order you expect, eg result001.png, result002.png, ... result010.png.
Thank you, snibgo! I will work with that.

Can you also tell me what this command means:

Code: Select all

%IM%convert
I was looking at your page (http://im.snibgo.com/spdsiz.htm) and I am confused about the percent sign before and after "IM". When I try using it on my Windows Server it doesn't recognize it. When I am trying to use the "convert" command, it is a Windows command and not a part of the IM. Where can I read more about this stuff?

Thank you so much for helping me! I truly appreciate it.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Converting Multiple Images into a PDF File

Post by snibgo »

I use an environment variable called IM, which is set to a directory that contains a v6 ImageMagick.

Code: Select all

f:\web\im>echo %IM%
c:\im\ImageMagick-6.9.5-3-Q16\
So my scripts use "%IM%convert" to run that particular version of IM. I have about 50 versions installed.

Another method is to tell IM at installation that you want it to add IM's directory to the front of your system path. Then you can just use "convert" and this will run IM's program, not the Microsoft program.
snibgo's IM pages: im.snibgo.com
cageybee
Posts: 5
Joined: 2017-03-21T15:16:49-07:00
Authentication code: 1151

Re: Converting Multiple Images into a PDF File

Post by cageybee »

snibgo wrote: 2017-03-22T09:26:30-07:00 I use an environment variable called IM, which is set to a directory that contains a v6 ImageMagick.

Code: Select all

f:\web\im>echo %IM%
c:\im\ImageMagick-6.9.5-3-Q16\
So my scripts use "%IM%convert" to run that particular version of IM. I have about 50 versions installed.

Another method is to tell IM at installation that you want it to add IM's directory to the front of your system path. Then you can just use "convert" and this will run IM's program, not the Microsoft program.
Got it. Thank you!
Post Reply