Converting images into pdf files with equal sizes?

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
User avatar
csanyipal
Posts: 2
Joined: 2015-01-03T02:42:21-07:00
Authentication code: 6789
Location: Central Europe
Contact:

Converting images into pdf files with equal sizes?

Post by csanyipal »

Hi,
on my Arch linux I'm using ImageMagick 6.9.0-2 Q16 x86_64 2014-12-31.

I have a directory with many ( over 300 ) jpg images.
These images are scanned pages from a book.

Images have following properties:
geometry: 900x1200
resolution: 180x180

from the first image to the 27. image but from 28. image this is changing:
geometry: 900x1200
resolution: 150x150

I do converting these images into pdf files with command:

Code: Select all

for i in *.jpg; do convert ${i} ${i/.jpg/.pdf}; done
Then I merge these pdf files into one pdf file with command:

Code: Select all

pdftk *.pdf cat output valami.pdf
So as a result I get not equal pdf page sizes because from the 28.pdf pages are bigger in the same merged document.

How can I get equal pdf pages using the convert tool?

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

Re: Converting images into pdf files with equal sizes?

Post by snibgo »

Have you tried changing the resolution so they all match? Use "-density 180" or "-density 150".
snibgo's IM pages: im.snibgo.com
User avatar
csanyipal
Posts: 2
Joined: 2015-01-03T02:42:21-07:00
Authentication code: 6789
Location: Central Europe
Contact:

Re: Converting images into pdf files with equal sizes?

Post by csanyipal »

snibgo wrote:Have you tried changing the resolution so they all match? Use "-density 180" or "-density 150".
I solve the problem with these commands:

Code: Select all

mogrify -resize x1000 *.jpg
for i in *.jpg; do convert -density x1000 -units PixelsPerInch ${i} ${i}; done
for i in *.jpg; do convert ${i} ${i/.jpg/.pdf}; done
pdftk *.pdf cat output resulting.pdf verbose
pdf2djvu -o resulting.djvu resulting.pdf
The resulting pdf and djvu document has all pages same sized.
However, I don't really know what I did. Can one explain the:

Code: Select all

convert -density x1000 -units PixelsPerInch
part of code and whether must I before that command to resize images to the same 1000 pixels hight?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK
Contact:

Re: Converting images into pdf files with equal sizes?

Post by snibgo »

csanyipal wrote:So as a result I get not equal pdf page sizes ...
I think the problem is that your images had different resolutions: 180 or 150. So the cure is to make them all the same resolution, with "-density".
snibgo's IM pages: im.snibgo.com
dowcet
Posts: 11
Joined: 2015-04-03T23:51:15-07:00
Authentication code: 6789
Contact:

Re: Converting images into pdf files with equal sizes?

Post by dowcet »

I was going to start a new question but this discussion seems closely related.

I have an image like this.

Format: JPEG (Joint Photographic Experts Group JFIF format)
Class: DirectClass
Geometry: 2560x1280+0+0
Resolution: 300x300
Print size: 8.53333x4.26667
Units: PixelsPerInch

A density of 300 results in a very low-resolution PDF. Through trial and error I figured out that I had to set `-density 72` to get a PDF of the same resolution. How does this work exactly? Is there not some argument that will maintain the same resolution regardless of density?
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 39 guests