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? |
Beta Was this translation helpful? Give feedback.
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. |
Beta Was this translation helpful? Give feedback.
-
So for example if the width and height of the generated image was |
Beta Was this translation helpful? Give feedback.
-
You would You would set |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
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. |
Beta Was this translation helpful? Give feedback.
-
What would the offset be set to? |
Beta Was this translation helpful? Give feedback.
-
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 |
Beta Was this translation helpful? Give feedback.
-
Amazing thank you Terry, I've updated my instructions in the previous comment |
Beta Was this translation helpful? Give feedback.
Thank you for your fast reply Terry. I managed to get it working but to make it clear for other people:
-sDEVICE=bbox
giving you the bbox of the item: