Exporting a PNG cropped to the barcode #113
|
I'm trying to generate a png of a datamatrix but its giving me this: I'm catting the following code to the ps file. 0 0 moveto
(123458) () /datamatrix /uk.co.terryburton.bwipp findresource exec
showpage
How can I remove the white space? |
Replies: 8 comments
|
To be accurate you would typically your would use a multi-pass process. First obtain the bounding box for the image. You'll need to use offset coordinates since GhostScript only calculates the bounding box for the first quadrant: Calculate the width and height and determine the translation (x,y) required to snap the lower-left basepoint to 0,0. Insert a Re-render the image with an adjusted basepoint and fixed page size: In all cases be sure to get the rounding right to avoid clipping the edge of the symbol. |
|
So for example if the width and height of the generated image was |
|
You would You would set |
|
Thank you for your fast reply Terry. I managed to get it working but to make it clear for other people:
...
%!PS
0 0 moveto (asda) (includetext rotation=45) /datamatrix /uk.co.terryburton.bwipp findresource exec
showpage
./gs -dBATCH -dNOPAUSE -sDEVICE=bbox genBarcode.ps
%%BoundingBox: -1 0 25 25
%%HiResBoundingBox: -0.008930 0.000000 24.011999 24.011999
0 0 moveto (asda) (includetext rotation=45) /datamatrix /uk.co.terryburton.bwipp findresource exec
translate 0.008930 0
showpage
You should have a png in your directory called |
|
It's important to include -sPAGEOFFSET= in the initial request, otherwise the parts of the image that extend below or to the left of the origin (e.g. human readable text in EAN symbols) will be ignored in the boundingbox calculation. |
|
What would the offset be set to? |
|
Anything sufficiently large to ensure that everything is translated into the first quadrant. This need to do this arises from a GhostScript limitation. I generally find |
|
Amazing thank you Terry, I've updated my instructions in the previous comment |

Thank you for your fast reply Terry. I managed to get it working but to make it clear for other people:
-sDEVICE=bboxgiving you the bbox of the item: