Create PDF with page title and multiple images

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
dogbert
Posts: 4
Joined: 2012-11-01T14:53:20-07:00
Authentication code: 67789
Location: Winnipeg, MB CANADA

Create PDF with page title and multiple images

Post by dogbert »

Hi all,
I am new to this forum and to the ImageMagick tools, so bear with me.

I have several thousand images that are grouped together using the information from a database file. These images, which can vary in size, are TIFFs that contain two scenes (the two scenes a generally the same height nd width).

What I need to do is create a PDF which has a title at the top of each page which gives the information required (including the total number of images in the PDF) along with the current page number with the total number of pages. The images are arranged 2x5 where scene 0 is on the left and scene 1 is on the right of every image and a border around the two scenes. The images must be set to the same width so that everything lines-up.

I am new to using montage and I have not been able to figure out how to create a title at the top of the page along with the the images, so what I did was to systematically create a title TIFF file, from a script, along with 5 images to create a temporary TIFF page and I continue this until I am done with the images of that group. After that, all the temporary TIFF images are copied together (tiffcp) and then a PDF is created from that with tiff2pdf. Another problem that I encountered with the PDF is that whenever the page did not contain exactly 5 images, the title and images would be pushed down the page and aligned at the bottom. To alleviate this problem, I ensure that I send a number of blank images so that there is always a multiple of 5. That is quite a bit clumsy and very slow and I am sure that there is a better way to do it, but I tried a few different ways and was not successful. :?

So to summarize here are the problems that I encountered:
1) How to create a dynamic page header
2) How to have all pages align at the top of the PDF (when there are less then 5 images on the page)

As an added bonus, I would like to know if it's possible to add to the PDF a search index that can be used to search from Adobe, for a certain image in the PDF?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create PDF with page title and multiple images

Post by fmw42 »

For the title and gravity, see

http://www.imagemagick.org/Usage/montage/

and especially Montage Control Settings

http://www.imagemagick.org/Usage/montage/#settings


As far as I know, IM will not be able to create an index. But I have never used Montage to create PDFs
dogbert
Posts: 4
Joined: 2012-11-01T14:53:20-07:00
Authentication code: 67789
Location: Winnipeg, MB CANADA

Re: Create PDF with page title and multiple images

Post by dogbert »

Hi Fred,
Thanks for you information.

I had already browsed through the montage usage web page before and it had not really helped me. Here are some of the problems that I was not able to figure out:
1) Part of the title is on the left, another part is in the middle and the other part is on the right. I thought of using the -gravity and -title for this and use it three times for the three sections, but it seems that only the last title is in effect and it seemed to always be centered -- it seems to ignore the -gravity option unless that is not in reference to the page (like it expect it to be)
2) I need to dynamically print at the top of each page the current page number along with the total number of pages. Ex: Page 1 of 3, Page 2 of 3 & Page 3 of 3. I had found a web page (http://www.imagemagick.org/script/escape.php) that describes the properties of the image, but I was not able to find one that can be used to identify the page. I found the scene variable, but is always shows as 0. When trying to use the -scene 1 when creating the PDF with montage, it gave me an error that it was an unrecognized option.
3) I was not able to figure out how to put the title at the top of the page -- it seems to float above the top of the first tiled image.
4) I want to have a bit of space at the bottom of the page so that the last image is not at the very bottom, but I was not able to figure out how to do this with a single montage command -- this is where I started creating a single page and adding a small blank image at the bottom to prevent that, but like I said the process I am using is clunky and slow.

Your help is greatly appreciate.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create PDF with page title and multiple images

Post by fmw42 »

I am not an expert on montage and have not used all the option you are and never tried with pdf files.

But it is hard to visualize what you want to do? Can you perhaps create a correct output that you can show us or a diagram of what you are trying to do. Also your command line may help, too. You can post to some free image hosting web site and then put the link here in your post. Does it work if you some other output format besides PDF. If so you can create it that way and then convert the result to PDF. Once we know what you are trying to do, we can try to recreate something similar to see about all these options you need.

Page numbers can be added at the bottom as labels as per the filename. Perhaps %p or %s, see http://www.imagemagick.org/script/escape.php. -scene 1 will change the starting scene number (associated with %s I believe) from 0 to 1. You may need to use -set label as per the example on the montage page.

As far a I know there is only one title for the whole montage. Titles for each image could be created by either appending a label image at the top of each image prior to running montange or just using the label at the bottom.

-gravity is only used to align the images themselves as far as I know.
dogbert
Posts: 4
Joined: 2012-11-01T14:53:20-07:00
Authentication code: 67789
Location: Winnipeg, MB CANADA

Re: Create PDF with page title and multiple images

Post by dogbert »

I have created a bogus sample since the actual images are from cheques which are obviously confidential. Here is the the sample TIFF file https://skydrive.live.com/embed?cid=EB9 ... Pacc4olCRQ and the same montage command to generate the PDF file https://skydrive.live.com/embed?cid=EB9 ... 8Ve4cM_1M4

I was not able to figure out how to print the page number since it was always coming out as 0 whether using %s or %p in the title. Also to get my whole title at the top of the page I had to put several spaces which wrecked the second line if ever I changed the value of the page number (not very elegant :().

To test what you suggested this is the command I used:

Code: Select all

montage -page letter -title "\nAccount: 1234567                                   Date: 01/06/2012 - 30/06/2012                                Page ## of ##\nTot. Images: 7                                                                                                                                           " -frame 6 -tile 2x5 -type Bilevel -geometry 628x+50+6 img0000[1-7].TIFF test.tif
I did the exact same command to create the PDF.

I can visually show you what I am trying to do:

Code: Select all

=======================================================================================================================================


   Account: 1234567                                       Date: 01/06/2012 - 30/06/2012                                  Page 1 of 2
   Tot. Images: 7

   ----------------------------------------------------------------  ---------------------------------------------------------------
   |                                                              |  |                                                             |
   |                                                              |  |                                                             |
   |                  (Cheque #1 front image)                     |  |                    (Cheque #1 back image)                   |
   |                                                              |  |                                                             |
   |                                                              |  |                                                             |
   ----------------------------------------------------------------  ---------------------------------------------------------------
   ----------------------------------------------------------------  ---------------------------------------------------------------
   |                                                              |  |                                                             |
   |                                                              |  |                                                             |
   |                  (Cheque #2 front image)                     |  |                    (Cheque #2 back image)                   |
   |                                                              |  |                                                             |
   |                                                              |  |                                                             |
   ----------------------------------------------------------------  ---------------------------------------------------------------
   ----------------------------------------------------------------  ---------------------------------------------------------------
   |                                                              |  |                                                             |
   |                                                              |  |                                                             |
   |                  (Cheque #3 front image)                     |  |                    (Cheque #3 back image)                   |
   |                                                              |  |                                                             |
   |                                                              |  |                                                             |
   ----------------------------------------------------------------  ---------------------------------------------------------------
   ----------------------------------------------------------------  ---------------------------------------------------------------
   |                                                              |  |                                                             |
   |                                                              |  |                                                             |
   |                  (Cheque #4 front image)                     |  |                    (Cheque #4 back image)                   |
   |                                                              |  |                                                             |
   |                                                              |  |                                                             |
   ----------------------------------------------------------------  ---------------------------------------------------------------
   ----------------------------------------------------------------  ---------------------------------------------------------------
   |                                                              |  |                                                             |
   |                                                              |  |                                                             |
   |                  (Cheque #5 front image)                     |  |                    (Cheque #5 back image)                   |
   |                                                              |  |                                                             |
   |                                                              |  |                                                             |
   ----------------------------------------------------------------  ---------------------------------------------------------------


=======================================================================================================================================


   Account: 1234567                                       Date: 01/06/2012 - 30/06/2012                                  Page 2 of 2
   Tot. Images: 7

   ----------------------------------------------------------------  ---------------------------------------------------------------
   |                                                              |  |                                                             |
   |                                                              |  |                                                             |
   |                  (Cheque #6 front image)                     |  |                    (Cheque #6 back image)                   |
   |                                                              |  |                                                             |
   |                                                              |  |                                                             |
   ----------------------------------------------------------------  ---------------------------------------------------------------
   ----------------------------------------------------------------  ---------------------------------------------------------------
   |                                                              |  |                                                             |
   |                                                              |  |                                                             |
   |                  (Cheque #7 front image)                     |  |                    (Cheque #7 back image)                   |
   |                                                              |  |                                                             |
   |                                                              |  |                                                             |
   ----------------------------------------------------------------  ---------------------------------------------------------------























=======================================================================================================================================
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create PDF with page title and multiple images

Post by fmw42 »

What is the page number represent? I am confused where that comes from? I presume you extract enough images for one page from your database and then montage them together and assign the page number from the database.


If the creation of the header is awkward in montage, then why not montage all the images and save as PNG or TIFF without a header. Then create a header image of the same width which has all the textual information including the "page number" using Label or Caption or Draw or Annotate. Then append the header to the top of the montaged image. Then convert the combined image to PDF.

see
http://www.imagemagick.org/Usage/text/
http://www.imagemagick.org/Usage/layers/#append

If the page number is for the group of images that need more than one pdf page, then compute how many you can put on one pdf page and then make multiple montages without headers. Add header images (as described above) to each montage. Save them as tiff or miff so that you get layers that will then convert to pages when you convert to pdf.
dogbert
Posts: 4
Joined: 2012-11-01T14:53:20-07:00
Authentication code: 67789
Location: Winnipeg, MB CANADA

Re: Create PDF with page title and multiple images

Post by dogbert »

Hi,

Thanks for your response.

Maybe I should have explained the (code) section that shows what I want as an end result. The "==" lines represent the page breaks and therefore want to display the current page number along with the total number of pages at the top of every page. That is why you see Page 1 of 2 and Page 2 of 2.

Essentially what you are suggesting is what I started doing:
I took all the images and tiled them 2x6 (5 cheques with their fronts on the left and their backs on the right) with a small blank image that contained the text that I wanted and inserted that every five images beginning as the first, so that this image would be on top of every page. For a certain month, this process took about 5 hours which was a bit slow but acceptable.

Three problems arose doing it this way:
1) Whenever the page did not contain exactly 5 cheques, that last page would align at the bottom in PDF format.
2) Since I was adding frames around the images this would add a frame to the title image as well (not what I wanted)
3) Their are a few businesses that have several hundred (close to one thousand) cheques and this one would fail because it ran out of memory -- I am not sure why because I was monitoring it and it was only using 3.5 GB of the 8 that the server has. I tried using the disk instead of memory and this took 3 hours to process this single business -- definitely not an option.

So to correct this I took it a step further: I would create a new temporary image of every cheque in the group and a adding frame around it and then assembled 5 cheques at a time (but I additionally added blank images (the size of a cheque) to make the last page have 5 cheques [real or blank]) to create a page of images which I later copied them all to the complete TIFF file which I then converted to PDF, and then the PDF looked like it was supposed to. The problem then was that this process is now taking 10 hours to complete which is way more time that I would expect it to take.

I think to reduce the processing time, I think it would be best if I let montage create the whole image, but I would need to find the solution to the three problems I identified:
1) Add blank images to pages that have less then 5 to correct the PDF problem -- It is fairly easy to do -- I do that now so this is not a problem.
2) I need to know it it's possible to add frames around only certain images (I don't want one around the title image nor do I want one around the blanks at the end of the page if the number of images does not end up as a multiple of 5)
3) How to process the dozen or so businesses that have a large amount of cheques -- i.e. take advantage of the whole 8 GB or more (we can add more if need be).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Create PDF with page title and multiple images

Post by fmw42 »

1) Add blank images to pages that have less then 5 to correct the PDF problem -- It is fairly easy to do -- I do that now so this is not a problem.
2) I need to know it it's possible to add frames around only certain images (I don't want one around the title image nor do I want one around the blanks at the end of the page if the number of images does not end up as a multiple of 5)
3) How to process the dozen or so businesses that have a large amount of cheques -- i.e. take advantage of the whole 8 GB or more (we can add more if need be).
1)To insert a black, add null: for the empty image
2)I do not believe that is possible with montage. You would have to add frames to each image you want and then use -+append to put them together
3) Don't know why it is failing other than running out of memory space. see http://www.imagemagick.org/Usage/files/#massive


You may be better off writing a script to do everything you want.
Post Reply