Free Support Forum -

DOCX to PDF Conversion throws Aspose.BarCode.BarCodeException using .NET


I try to convert a Word to Pdf. This usually works great, but when I’m using DISPLAYBARCODE fields, I become an error message instead of a barcode in the PDF document: “Error! Bar code generator is not set.”
Ok, I found some sample code on your site:
But using the sample, I get the error from the BarcodeGenerator: “Can’t render barcode: not enough space”
I will attach the word document and a small example.

kind regards
Peter (16.3 KB) (9.9 KB)


We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-22064. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.


It is to inform you that the issue which you are facing is actually not a bug in Aspose.Words. So, we have closed this issue (WORDSNET-22064) as ‘Not a Bug’.

Your issue is related to Aspose.BarCode. So, we have moved this forum thread to Aspose.BarCode forum where you will be guided appropriately.

We have observed the issue and logged it in our database for further investigation. You will be notified here once any update is ready for sharing.

This issue is logged as:
BARCODENET-37772 - DOCX to PDF Conversion throws Aspose.BarCode.BarCodeException using custom barcode generator (15.9 KB)

  1. 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

  1. 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.

  1. 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

Thank you for your help.
I added a second pass, when generating the barcode. The size of the image, depends also on the text length. So I need a default size of the barcode with the given text, before I can scale.

So in the first run, I generate a barcode image without any size specification.
And with the size of this barcode image, I generate a second where I can scale.

kind regards

Yes, this is the best solution in your case.