Convert JPG to PDF in Multiple Pages

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
Paulohpmagalhaes
Posts: 5
Joined: 2016-10-07T06:02:34-07:00
Authentication code: 1151

Convert JPG to PDF in Multiple Pages

Post by Paulohpmagalhaes »

Hello guys,
I have a huge image, lets say 1000x7000 and I would like to convert to PDF, but fit the width in the page and split the height in multiple pages.

When I Use the simple command below, the page in PDF is adjusted according the image size:

Code: Select all

C:\Program Files\ImageMagick-7.0.3-Q16>convert.exe c:\temp\teste.jpg c:\temp\teste.pdf
When I use the -page A4 parameter the Image is resized to fit in one page only:

Code: Select all

convert.exe c:\temp\teste.jpg -page A4 c:\temp\teste.pdf
What parameter should I user?

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

Re: Convert JPG to PDF in Multiple Pages

Post by snibgo »

How many pages do you want to split it across? I'll assume you want 7 pages. You might do it like this:

Code: Select all

convert c:\temp\teste.jpg -crop 1x7@ +repage c:\temp\teste.pdf
snibgo's IM pages: im.snibgo.com
Paulohpmagalhaes
Posts: 5
Joined: 2016-10-07T06:02:34-07:00
Authentication code: 1151

Re: Convert JPG to PDF in Multiple Pages

Post by Paulohpmagalhaes »

Thanks for the answer.
I want as many pages as needed. It could be one, it could be ten. It will depend on the height of the image which can change...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert JPG to PDF in Multiple Pages

Post by snibgo »

"crop x1000" or some other number might suit your needs better. This would give you 1000 rows per page, but the last page could have fewer.
snibgo's IM pages: im.snibgo.com
Paulohpmagalhaes
Posts: 5
Joined: 2016-10-07T06:02:34-07:00
Authentication code: 1151

Re: Convert JPG to PDF in Multiple Pages

Post by Paulohpmagalhaes »

Thank you again snibgo for the reply.

The "crop" parameter is a improvement, but I would like to have pages in A4 format with margins and centered so People can print in paper. I tried the -page a4 but didin't work with crop.

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

Re: Convert JPG to PDF in Multiple Pages

Post by snibgo »

For margins, "-repage" is useful. For example, if your input is 1000 pixels wide:

Code: Select all

convert c:\temp\teste.jpg -crop x1414 -repage 1200x1614+100+100 c:\temp\teste.pdf
snibgo's IM pages: im.snibgo.com
Paulohpmagalhaes
Posts: 5
Joined: 2016-10-07T06:02:34-07:00
Authentication code: 1151

Re: Convert JPG to PDF in Multiple Pages

Post by Paulohpmagalhaes »

Thank you again for the reply but I wasn't able to export in PDF like I expected. I have searched in the community, and in the command line reference but still no solution. It seems to work when I export to gif, but not to pdf..

Here is the link of a image of example and the PDF expected (I converted using PDF printer)

Image:
http://ntlh.com.br/wp-content/uploads/2 ... xample.jpg

PDF:
http://ntlh.com.br/wp-content/uploads/2 ... xample.pdf

Again, Thank you in advance...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert JPG to PDF in Multiple Pages

Post by snibgo »

The PDF contains four images, one per page. They have different heights: 1580, 1579, 1580 and 1085.

So you need to explicitly crop with those heights.
snibgo's IM pages: im.snibgo.com
Paulohpmagalhaes
Posts: 5
Joined: 2016-10-07T06:02:34-07:00
Authentication code: 1151

Re: Convert JPG to PDF in Multiple Pages

Post by Paulohpmagalhaes »

The idea would be to use -crop x1580. The last one will be the remainder. If I use:

Code: Select all

convert c:\temp\example.jpg -crop x1580 +repage c:\temp\example.pdf
I will have this:

http://ntlh.com.br/wp-content/uploads/2 ... esteA1.pdf


It's almost what I want, I just need in printable format (A4 with margin).
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Convert JPG to PDF in Multiple Pages

Post by snibgo »

Above, I suggested you use "-repage" for the margins. Or you may prefer to use "-borders".
snibgo's IM pages: im.snibgo.com
Post Reply