Hi,
I am checking your library Aspose Barcode for the possibility in using it in the system to add barcode in pdf. In the system I need to fit a barcode in a place holder and the placeholder can vary in size (will always be larger than the minimum size needed to fit data), however I found the following 4 issues/concerns when trying to get it working
When I used the code below
//encode array to string
StringBuilder strBld = new StringBuilder();
foreach (byte bval in encodedArr)
{
strBld.Append((char)bval);
}
BarcodeGenerator generator = new BarcodeGenerator(EncodeTypes.DataMatrix, strBld.ToString());
generator.Parameters.Barcode.CodeTextParameters.Location = CodeLocation.None;
generator.Parameters.Barcode.DataMatrix.DataMatrixEncodeMode = DataMatrixEncodeMode.Full;
generator.Parameters.Barcode.Padding.Bottom.Pixels = 1;
generator.Parameters.Barcode.Padding.Left.Pixels = 1;
generator.Parameters.Barcode.Padding.Right.Pixels = 1;
generator.Parameters.Barcode.Padding.Top.Pixels = 1;
Using code above it results in the barcode below
However if I add the below code to use autosizemode nearest instead of none:
generator.Parameters.AutoSizeMode = AutoSizeMode.Nearest;
generator.Parameters.ImageHeight.Pixels = 60;
generator.Parameters.ImageWidth.Pixels = 60;
The result is the below.
image.png (5.3 KB)
1)My issue is that when setting nearest it is ignoring the fact that I set padding to 1,is there a correct way to force the padding when using nearest ( this happens with any image height and image width)
2)Another concern is that if the ImageHeight and ImageWidth are not the same size for example if I set the height to 60 and width to 280 it does not take the whole width(Also notice that as mentioned in one, the top and bottom margins are not 1 pixel neither).
generator.Parameters.AutoSizeMode = AutoSizeMode.Nearest;
generator.Parameters.ImageHeight.Pixels = 40;
generator.Parameters.ImageWidth.Pixels = 180;
The result is the below
image.png (5.2 KB)
I tried to use the aspect ration to solve it but as seen from image below it still does not take the whole size(might be due to the padding as mentioned in 1)
generator.Parameters.Barcode.DataMatrix.AspectRatio =(float)40 / 180;
The result is the below
image.png (9.7 KB)
-
Referring to no 2 when setting the aspect ratio, according to Generate Data Matrix Barcodes in C#|Documentation “In general, the Aspect Ratio value should be set to 1.”. Is there any limitation to what the aspect ratio can be set?
-
Also referring to no 2, when setting aspect ratio it seems that the barcode is stretched out is there a way to safely calculate and set the rows and columns according the aspect ratio so that barcode remains valid but not stretched out?