For Programmers: Free Programming Magazines  


Home > Archive > PostScript > August 2007 > How can I trim the margin when converting from PS/PDF to PNG?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author How can I trim the margin when converting from PS/PDF to PNG?
Tassilo Horn

2007-08-25, 10:12 pm

Hi,

I use GPL GhostScript 8.60 to convert PostScript or PDF files to a set
of PNG files using the command:

gs -dNOPAUSE -sDEVICE=png16m -dTextAlphaBits=4 -dBATCH \
-dGraphicsAlphaBits=4 -dQUIET -r100 -sOutputFile=page-%d.png \
foo.pdf

Now I'd like that the margins of the PS/PDF files are cut off, so that
the resulting PNGs don't have a border at all. Is that possible with
ghostscript somehow?

ImageMagick's convert tool can do that with its -trim option, but
convert is awfully slow compared to gs.

Thanks for any pointers,
Tassilo
Govert J. Knopper

2007-08-26, 4:27 am

> I use GPL GhostScript 8.60 to convert PostScript or PDF files to a set
> of PNG files using the command:
>
> gs -dNOPAUSE -sDEVICE=png16m -dTextAlphaBits=4 -dBATCH \
> -dGraphicsAlphaBits=4 -dQUIET -r100 -sOutputFile=page-%d.png \
> foo.pdf
>
> Now I'd like that the margins of the PS/PDF files are cut off, so that
> the resulting PNGs don't have a border at all. Is that possible with
> ghostscript somehow?
>
> ImageMagick's convert tool can do that with its -trim option, but
> convert is awfully slow compared to gs.



This is for EPS files: http://dsanta.users.ch/resources/soft/epsbboxfit.pl

I do something similar for PDF files in a Windows .net application, using
GhostScript to find the bounding box of the imaged area and iTextSharp to
create a new PDF with the content of the original file and the size of that
bounding box. Next step for you would be to convert the cropped PDF to PNG.

Govert

http://www.noliturbare.com


Tassilo Horn

2007-08-27, 8:08 pm

"Govert J. Knopper" <check_my_site_4_contact> writes:

Hi Govert,

> This is for EPS files:
> http://dsanta.users.ch/resources/soft/epsbboxfit.pl
>
> I do something similar for PDF files in a Windows .net application,
> using GhostScript to find the bounding box of the imaged area and
> iTextSharp to create a new PDF with the content of the original file
> and the size of that bounding box. Next step for you would be to
> convert the cropped PDF to PNG.


Thanks a lot. I'll have a look at it.

Bye,
Tassilo
--
How many roundhouse kicks does it take to get to the center of a tootsie
pop? Just one. From Chuck Norris.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com