PDF: use-trimbox not working

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
blahor

PDF: use-trimbox not working

Post by blahor »

Hi again,

I'm trying to convert pdfs and automatically crop the area outside the trimbox, but it's not working as expected.
My command (ImageMagick 6.2.4 02/10/07 Q16):

Code: Select all

convert -define pdf:use-trimbox=true -density 300 foo.pdf -resize 600 bar.jpg
If i set -define pdf:use-trimbox=true nothing happens, the resulting image is showing the whole pdf:
result


So I copied the trim value to crop inside the pdf and tried:

Code: Select all

convert -define pdf:use-cropbox=true -density 300 foo.pdf -resize 600 bar.jpg
This time the image is cut right, but it's still using the original page size resulting in a big white border:
result

So basically I have two questions:
* how do i get rid off the white border when using cropbox? did i miss a +repage or something?
* why doesn't use-trimbox work?

EDIT:

seems like -trim +repage will remove the white borders:

Code: Select all

 convert -define pdf:use-cropbox=true -density 300 -trim +repage foo.pdf -resize 600x bar.jpg
But I'm afraid this will remove parts of images which are starting white inside the trimbox.
blahor

Re: PDF: use-trimbox not working

Post by blahor »

I've solved the problem with a little workaround:

I made a perl script that checks the pdf file for a TrimBox and writes the trimbox values to the CropBox property if necessary. Then i use ghostscript to generate a new cropped pdf (gs -sDEVICE=pdfwrite -dUseCropBox -sOutputFile=out.pdf -_ < in.pdf).
The cropped pdf is used for further conversions with IM.

LMK if there's an easier way...
wisepeace

Re: PDF: use-trimbox not working

Post by wisepeace »

blahor wrote:I've solved the problem with a little workaround:

I made a perl script that checks the pdf file for a TrimBox and writes the trimbox values to the CropBox property if necessary. Then i use ghostscript to generate a new cropped pdf (gs -sDEVICE=pdfwrite -dUseCropBox -sOutputFile=out.pdf -_ < in.pdf).
The cropped pdf is used for further conversions with IM.

LMK if there's an easier way...
Are there any ImageMagick admins that have a better or similar solution for this?
basstradamus
Posts: 3
Joined: 2010-02-11T07:54:13-07:00
Authentication code: 8675309

Re: PDF: use-trimbox not working

Post by basstradamus »

Does anybody knows why pdf:use-trimbox=true doesn't work at all???
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: PDF: use-trimbox not working

Post by anthony »

If it is not working, you should report a bug in the bugs area. But be sure it is definatally wrong, and include examples files.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply