How can I resize a PDF and keep a right blank margin

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?".
michellux
Posts: 18
Joined: 2014-12-03T08:07:28-07:00
Authentication code: 6789

How can I resize a PDF and keep a right blank margin

Post by michellux »

Hello,

Hope you can help me on my problem. I am working under Windows 7.
I have a .pdf file to resize, for example 95%, and convert it in .jpg. That is working fine. But if I take my .jpg to transform it back in .pdf, the image is automaticaly resized to take all the width of the document.
What I want after resizing is to keep a right blank vertical "margin" in the final .pdf document, and naturally, this should be done automatically, as I have many documents to treat.
Is it possible and how ?
Thanks for your help.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can I resize a PDF and keep a right blank margin

Post by snibgo »

You can set the page size for the PDF. For example, if the input is 200x300 pixels:

Code: Select all

convert r.jpg -page 300x300 r2.pdf
This creates a 100 pixel margin on the right.
snibgo's IM pages: im.snibgo.com
michellux
Posts: 18
Joined: 2014-12-03T08:07:28-07:00
Authentication code: 6789

Re: How can I resize a PDF and keep a right blank margin

Post by michellux »

Sorry, but I should have done something wrong as I did not get the result I expect.
Here are the commands I entered :
CONVERT MYPDF.PDF -RESIZE 95% MYPDF.JPG
This gave me one .jpg file for each page of my .pdf file. The dimensions of each page are : 565x800 dpi. Then I converted back in .pdf :
CONVERT MYPDF*.JPG -PAGE 595X842 MYNEWPDF.PDF
595x842 is the normal size for a A4 format page, and is bigger than the previous 565x800 dimensions for the .jpg, but I do not have any margin on my new document...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can I resize a PDF and keep a right blank margin

Post by snibgo »

This gives me two pages, each with a margin at top and right:

Code: Select all

%IM%convert -size 565x800 gradient:red-blue r1.jpg
%IM%convert -size 565x800 gradient:red-lime r2.jpg

%IM%convert r1.jpg r2.jpg -page 595x842 r2.pdf
This is with IM v6.9.0-9, on Windows 8.1. What version IM are you using?
snibgo's IM pages: im.snibgo.com
michellux
Posts: 18
Joined: 2014-12-03T08:07:28-07:00
Authentication code: 6789

Re: How can I resize a PDF and keep a right blank margin

Post by michellux »

Well, I understand now ... I have IM v1 !!! :) I will download a "fresh" version and tra again ...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can I resize a PDF and keep a right blank margin

Post by snibgo »

v1! Gosh. Take it to a museum.

Get a current Windows binary download from http://www.imagemagick.org/script/binar ... hp#windows
snibgo's IM pages: im.snibgo.com
michellux
Posts: 18
Joined: 2014-12-03T08:07:28-07:00
Authentication code: 6789

Re: How can I resize a PDF and keep a right blank margin

Post by michellux »

In fact, I confused with IM display version which is always 1. Nevertheless, I started a complete new install, and now it works perfectly. Thanks.
But now, the quality of the new .pdf file is very poor comparing with the original .pdf. Is there any solution to keep the original quality of the document ? I tried with doubling the DPI resolution, but it is still insufficient.
And another question, if I can permit, is it possible to do all the process in one phase, without using any .jpeg files ?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can I resize a PDF and keep a right blank margin

Post by snibgo »

For best quality, do not use jpeg for intermediate files. In fact, never use jpeg at all.

Yes, this can be done without intermediate files.

Code: Select all

convert mypdf.pdf -resize 95% -page 595x842 mynewpdf.pdf
ImageMagic is a raster image processor. Raster images are made of pixels. PDF files can contain raster images or vectors (like text) or both. The "-density" setting is normally required, eg:

Code: Select all

convert -density 300 mypdf.pdf -resize 95% -page XXXxYYY mynewpdf.pdf
For XXX and YYY, use some other numbers (because each page from the PDF will be bigger).
snibgo's IM pages: im.snibgo.com
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can I resize a PDF and keep a right blank margin

Post by snibgo »

michellux wrote:In fact, I confused with IM display version which is always 1.
Ignore that. The version number comes from:

Code: Select all

convert -version
snibgo's IM pages: im.snibgo.com
michellux
Posts: 18
Joined: 2014-12-03T08:07:28-07:00
Authentication code: 6789

Re: How can I resize a PDF and keep a right blank margin

Post by michellux »

If I try CONVERT in one step with -density parameter, I lost my right margin (?!). If do it without -density parameter, I keep my margin, but not the quality ...
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can I resize a PDF and keep a right blank margin

Post by snibgo »

Keep it simple. Change one thing at a time. Don't combine steps until each one works.

Code: Select all

convert mypdf.pdf -resize 95% myfile.png
(Note: I use PNG, not JPG.)
What size is each PNG?

Code: Select all

identify myfile-0.png
Then decide on suitable values for "-page".
snibgo's IM pages: im.snibgo.com
michellux
Posts: 18
Joined: 2014-12-03T08:07:28-07:00
Authentication code: 6789

Re: How can I resize a PDF and keep a right blank margin

Post by michellux »

I have 8 files PNG 565x800 565x800+0+0 16-bit sRGB size between 0.78 to 1.438 MB
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can I resize a PDF and keep a right blank margin

Post by snibgo »

Now add "-density".

Code: Select all

convert -density 300 mypdf.pdf -resize 95% myfile.png
What size is each PNG?

Code: Select all

identify myfile-0.png
snibgo's IM pages: im.snibgo.com
michellux
Posts: 18
Joined: 2014-12-03T08:07:28-07:00
Authentication code: 6789

Re: How can I resize a PDF and keep a right blank margin

Post by michellux »

size is now between 5.9 and 14.1 MB
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How can I resize a PDF and keep a right blank margin

Post by snibgo »

MB don't matter. How many pixels? Is the quality better?
snibgo's IM pages: im.snibgo.com
Post Reply