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

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

Post by michellux »

yes quality is higher, the PNG is now 2356x3333
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 »

Yes quality is higher. PNG file is now 2356x3333 dpi
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 »

Good. So now:

Code: Select all

convert myfile-*.png -page 2600x3333 r2.pdf
... should give you a right-margin.

If that works, try it in one step:

Code: Select all

convert -density 300 mypdf.pdf -resize 95% -page 2600x3333 mynewpdf.pdf
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 »

Thanks a lot Snibgo ! It works perfectly and I understood the way to do. But, there is another point, which is the final weight of the document. So I tried different densities to find the best compromise between quality and weight. (original PDF is 2MB, resized pdf - density 300 dpi: 155 MB, 150 dpi: 40 MB, 100 dpi: 18 MB). I know ImageMacker is not Acrobat, but no way to lighten the document without loosing quality ?
pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

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

Post by pipitas »

michellux wrote: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.
Just in case you are going this route to resize a PDF (via ImageMagick) as an "act of desperation" because...
  • you are not aware of any other way to add an extra margin to the PDF pages (or to resize them),
  • but you are not really interested (which you may nevertheless still be for some reason beyond my knowledge) to convert your PDF fonts/vectors to mince-meated (and either bad quality or big file size) full-page pixel graphics (it's just the price you pay for getting the resizing)...
...there are also ways to preserve your PDF quality and still get the resize done.

Here is a method to get this done with Ghostscript:

1. First, create a demo PDF file with 2 pages (A4) 595 x 842 pt each, using Ghostscript:

Code: Select all

gs                                            \
 -o origin.pdf                                \
 -sDEVICE=pdfwrite                            \
 -g5950x8420                                  \
 -c "1 0 0 setrgbcolor 0 0 595 842 rectfill   \
     1 setgray                                \
     10 10 575 822 rectstroke                 \
     /Helvetica findfont 36 scalefont setfont \
     20 800 moveto                            \
     (Page 1) show showpage                   
     0 1 0 setrgbcolor                        \
     0 0 595 842 rectfill                     \
     1 setgray                                \
     10 10 575 822 rectstroke                 \
     20 800 moveto                            \
     (Page 2) show  showpage"
2. Second, place the demo PDF on pages with dimensions of 630 x 842 pt (you use your own PDF for this of course!), creating temp-630x842pt.pdf

Code: Select all

gs                     \
 -o temp-630x842pt.pdf \
 -sDEVICE=pdfwrite     \
 -g6300x8420           \
  origin.pdf
3. Last, place the intermediate PDF file on pages with dimensions of 595 x 842 pt again (this time using "scale to fit"), creating rescaled.pdf:

Code: Select all

gs                  \
 -o rescaled.pdf    \
 -sDEVICE=pdfwrite  \
 -g5950x8420        \
 -dPDFFitPage       \
 -f temp-630x842pt.pdf
Voila -- your original PDF is rescaled, and you've avoided the mince-meating of all your vector and font elements into purely raster data! (Unless there is a valid reason why you wanted this rasterization in the first place!). Here is a picture that shows the steps:

Image

On the left is the original page. In the center is the original page, placed on a page that is 630 pts wide. On the right is the original page as it appears after the page from the center image is scaled back to A4.
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:I know ImageMacker is not Acrobat, but no way to lighten the document without loosing quality ?
I expect the method shown by pipitas keeps the filesize small, while retaining all the quality. This is because it does not not convert vectors into pixels.

For processing PDF files, Ghostscript is a more natural tool than ImageMagick.
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 »

@ Snigbo : ok I understand better now. Thanks for all you did. :)
@ Pipitas : Thanks. I still work on your solution. I cannot see the image you put in. I'll give my email in MP. Can you please send it to me ?
pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

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

Post by pipitas »

michellux wrote:I cannot see the image you put in.
Anybody else who cannot see the image?!?
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

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

Post by fmw42 »

I see all three of your images that have been concatenated into one image and the final images shows fine for me. It might be a browser issue?
pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

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

Post by pipitas »

fmw42 wrote:I see all three of your images that have been concatenated into one image
Yes, that's how it is supposed to be....
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 »

It shows fine for me. It can be downloaded from http://i.stack.imgur.com/o5mVu.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 »

It is McAfee Web Gateway (used by my company) which blocked the URL. I asked the hotline to send me the file :)
pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

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

Post by pipitas »

Maybe we should ask the ImageMagick developers if they could start to create a new '-metric pr0n' measurement method.

It would return a number in the range of {0..100} telling the probability in percent of an image being NSFW. McAffee could then make use of it and let pass all images which are below a threshold of, say, 10%...

:)
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 really don't know Ghostscript. I downloaded and installed it, and Gsview too, but I really don't see how to do the 3 phases you describe ...
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 »

Why should I do Phase 1 "Creating demo.pdf" if in phase 2 I use my pdf file ?
Post Reply