ConsoleApp2Updated.zip (15.9 KB)
- Current issue is not a bug. It exists because BarcodeGenerator cannot fit barcode to requested size. Fix current example you can it in two ways:
- Set quiet zone(zone around barcode) to zero. Quiet zone padding is calculated in points(1/72 of inch) and this reduces painted barcode area:
//set quiet zone to 0
generator.Parameters.Barcode.Padding.Left.Pixels = 0;
generator.Parameters.Barcode.Padding.Top.Pixels = 0;
generator.Parameters.Barcode.Padding.Right.Pixels = 0;
generator.Parameters.Barcode.Padding.Bottom.Pixels = 0;
- Increase scale coefficient:
const float scale = 3.5f; // Empiric scaling factor for converting Word barcode to Aspose.BarCode
- About the problem.
Aspose.BarCode can generate barcode images in three modes:
- AutoSizeMode.None – in this mode Parameters.ImageWidth/ImageHeight is ignored and barcode size depends on Parameters.Barcode.XDimension.
- AutoSizeMode.Nearest – in this mode XDimension is ignored and barcode engine tries to find nearest image without size distortions close to Parameters.ImageWidth/ImageHeight
- AutoSizeMode.Interpolation - in this mode XDimension is ignored and barcode engine fits barcode image to Parameters.ImageWidth/ImageHeight even with unprorotional scaling which can damage barcode.
Aspose.Words.Fields.BarcodeParameters doesn’t contain any barcode size (it has only SymbolHeight sometimes) and we can extract possible barcode image size only empirically (with magic sizing coefficients).
When Aspose.BarCode engine detects situation that barcode image can be generated only with strong damage, which makes it unrecognizable, the engine throws exception. Upper exception is thrown because QR cell size with default padding was less then 1 pixel which strongly damages barcode.
- How the problem could be solved.
3.1 We can do hotfix to the documentation and update zeroing quiet zone as default and update magic coefficient.
3.2 However, proper solution here could be as updating Aspose.Words.Fields.BarcodeParameters API and adding there required barcode size in twips/inches/millimeters