Error! Bar code generator is not set. Aspose.Words.Document.save(".pdf")

I got a .docx template file with a DisplayBarcode Field Code to paint QR codes which is saved correctly in .docx but when I try to save it in pdf the file does not show the QR code but shows the string “Error! Bar code generator is not set”.

DOCX:
image.png (110.7 KB)

PDF:
image.png (54.0 KB)

I tried to instantiate the field Document.FieldOptions.BarcodeGenerator with a custom class which implements IBarCodeGenerator but I do not know how to build the QR image inside the method GetBarcodeImage.

Is there another way to avoid the issue?

Note: I am using the last version of Aspose.Words.

Thanks.

@bizagi-engineering Most likely in your document you are using DisplayBarcode field like the following: in.docx (12.1 KB)

{ DisplayBarcode "http://www.microsoft.com" QR \q 3 }

In this case you should use a customer barcode generator to update value of this field. You can implement IBarcodeGenerator/) to achieve this. For example see CustomBarcodeGenerator implementation using Aspose.Barcode.
Then using the following code:

Document doc = new Document(@"C:\Temp\in.docx");
doc.FieldOptions.BarcodeGenerator = new CustomBarcodeGenerator();
doc.Save(@"C:\Temp\out.pdf");

You will get the desired output: out.pdf (2.6 KB)

1 Like

Thanks, it works great, with the following remarks:

  • For invalid parameters like scaling factor 1% for a QR code, this code throws exceptions. Word would ignore them and in this case scale 100%.
  • Invalid code values like “INVALID96385074” for EAN8 result in some bar code with Aspose, but Word would print an error message to the document.
  • Scaling for QR codes works, but AutoSizeMode must stay Nearest, or else an error occurs because of CustomBarcodeGenerator.cs:168 (in our example scaling was \s55), so this code line must go to an else branch.
  • new BarcodeGenerator(EncodeTypes.None) would throw an exception before you return null in CustomBarcodeGenerator.cs:117
  • Your example files like out.pdf are not accessible to everyone: “Sorry, this file is private. Only visible to topic owner and staff members.”

Again, you made our day. Thank you!

@GEDAT Thank you for your feedback. The issues you have described are not related to Aspose.Words itself, but to the implementation of IBarcodeGenerator/), which uses Aspose.Barcode in the example. You can report the issues in Aspose.Barcode support forum, my colleagues will help you shortly.
Regarding the last point, you are right, only topic starter and Aspose staff can download attachments in the forum. So if you encounter an issue it is better to start your own topic to be able to download files attached by Aspose staff.

1 Like