Bug 690284 - white border is added while fake-printing pdf to png
Summary: white border is added while fake-printing pdf to png
Status: RESOLVED WORKSFORME
Alias: None
Product: Ghostscript
Classification: Unclassified
Component: Graphics Library (show other bugs)
Version: 8.64
Hardware: PC Linux
: P4 normal
Assignee: Default assignee
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-02-11 09:59 UTC by Maciej Pilichowski
Modified: 2009-02-12 11:08 UTC (History)
0 users

See Also:
Customer:
Word Size: ---


Attachments
black.pdf (5.57 KB, application/pdf)
2009-02-11 12:46 UTC, Maciej Pilichowski
Details
gs-black.png (1.14 KB, image/png)
2009-02-11 13:59 UTC, Ralph Giles
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Maciej Pilichowski 2009-02-11 09:59:16 UTC
The problem is the same as in ImageMagick. I am trying to convert pdf file into 
png -- in GS instead of converting I am printing the file. And the problem is, 
no matter what I do, in result I get the image but with huge white border, the 
image itself is pushed into lower, left corner.

It is easiest to see in this example, single page pdf, whole page is black, 300 
dpi:
http://www.imagebam.com/image/699efd25471451

I execute:
gs -q -sDEVICE=pnggray -dBATCH -dNOPAUSE -dFirstPage=1 -dLastPage=1 -r300 -sOutputFile=black.png 
black.pdf 2>&1

I should get the same black rectangle, instead I get this:
http://www.imagebam.com/image/c27a9126403474

One note: from what I see specifying the density is irrelevant here, the image 
gets bigger or smaller, but the white border remains.

[ sorry if the component is wrong, this is my first report at this site ]
Comment 1 Alex Cherepanov 2009-02-11 10:22:46 UTC
I guess, you need to use -dUseCropBox option but it's hard to tell
without a sample PDF file. If -dUseCropBox doesn't work for you, please
attach your PDF file to the bug report.
Comment 2 Maciej Pilichowski 2009-02-11 12:43:57 UTC
The result is changed, but there is still some white leftovers. 

Attachment follows (btw. this pdf is from converting black png image into pdf).
Comment 3 Maciej Pilichowski 2009-02-11 12:46:08 UTC
Created attachment 4788 [details]
black.pdf
Comment 4 Ralph Giles 2009-02-11 13:59:46 UTC
Created attachment 4790 [details]
gs-black.png

Seems to work for me. Attaching the output of

$ bin/gs -dUseCropBox -r300 -sDEVICE=pnggray -o gs-black.png black.pdf

I do see a small white border looking at the attached pdf in evince. The image
matrix does look incorrect to fill the crop box:

/MediaBox [0 0 640 400]
/CropBox [0 0 154 96]
...
153.6 0 0 96.0002 0 0 cm
/Im0 Do

If I change the matrix to match the CropBox dimensions, the remaining border
goes away.
Comment 5 Maciej Pilichowski 2009-02-12 00:23:11 UTC
The white remains are identical to mine when I added cropbox. But you have to 
modify the matrix by hand, so it is a workaround, not a solution (but thank you 
for the tip). My point is -- it should be automatic.

I can convert png to pdf file 100% automatically, and the result is identical 
to the source. Now, I should be able to do the same with converting pdf to png.
Comment 6 Ralph Giles 2009-02-12 02:24:24 UTC
My claim in #4 is that the pdf is not 100% identical to the source png. The
problem is that the file draw the image slightly smaller than the CropBox;
Ghostscript appears to be rendering that faithfully. Perhaps Imagemagick is
rounding the CropBox but not the image matrix. Or just rounding the two differently.

In printing, it is common to extend the border colours outside the CropBox
(so-called "full bleed") to avoid issues like this. Especially since an actual
physical crop is unlikely to be precise. Imagemagick doesn't seem to be doing
this either. If you know the border colour you might be able to work around by
adding '-background black', for example, to your convert command line.
Comment 7 Ray Johnston 2009-02-12 10:03:38 UTC
Adobe Acrobat 8 and 9 both show the white line along the right hand side, the
same as Ghostscript.

We are correctly rendering the PDF, closing as WORKSFORME
Comment 8 Maciej Pilichowski 2009-02-12 11:04:38 UTC
Ok, I just want to ensure -- the problem with printing .pdf to .png using GS is 
caused by incorrectly constructed .pdf file (by ImageMagick)?

Did you understand you right? (if yes, I think it would be the best to post a 
report again IM but for .png -> .pdf conversion, and after the fix in IM test 
it again in GS for .pdf -> .png "printing").
Comment 9 Ralph Giles 2009-02-12 11:08:16 UTC
Yes, the problem you're having is from Imagemagick. Ghostscript is rendering the
created pdf correctly.