We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Mail merge + mergebarcode error

Hi!

I get “Error! Bar code generator is not set.” in the output pdf.
I’m using {MERGEBARCODE fieldname QR} in the dotx template.
What should I to do in my Java code?

Thank you!

Hi Kálmán,

Thanks for your inquiry.

Aspose.Words for Java has an interface for generating custom barcodes which makes it very easy to use Aspose.Words for Java and Aspose.BarCode for Java together to render barcode images in output documents. For example, you can load a DOC, OOXML or RTF document containing DISPLAYBARCODE Field into Aspose.Words for Java, provide your implementation of custom barcode generator and save to fixed page formats such as PDF, XPS etc. A typical DISPLAYBARCODE field has following syntax:

{ DISPLAYBARCODE “SomeData” QR \h 720 }

Please refer to the following article for more details:
How to Generate a Custom BarCode Image for DISPLAYBARCODE Field

Best regards,

Awais Hafeez
Aspose - File Format APIs

Keep in touch! We’re on Twitter and Facebook

I ment MERGEBARCODE (as in title), not displaybarcode (as in description), my bad, sorry.
Does mergebarcode also requires Aspose.BarCode? Do we have to buy it, when we already bought Aspose.word.

Hi Kálmán,

Thanks for your inquiry.

As mentioned in its name, the MERGEBARCODE field updates during mail merge. So, it not only requires implementing a barcode generator, but also performing a mail merge. Please note that during the mail merge operation, the MERGEBARCODE field is converted to DISPLAYBARCODE field. Please see MergeBarcode_Template.zip (9.1 KB) and try using the following code:

Document doc = new Document("D:\\temp\\MergeBarcode_Template.docx");

// Set custom barcode generator
doc.getFieldOptions().setBarcodeGenerator(new CustomBarcodeGenerator());

doc.getMailMerge().execute(new String[] { "First", "Second" },
        new Object[] { "0000000000000000", "1111111111111111" });

doc.save("D:\\temp\\awjava-17.6.docx");

Hope, this helps.

Best regards,

Cannot download the zip : “Sorry, this file is private. Only visible to post creator and staff members.”

I’ve tried this (Barbecue : http://barbecue.sourceforge.net/)
The “barcode.png” contains the expected barcode image, but the pdf output does not. At least the exception message is gone.

doc.getFieldOptions().setBarcodeGenerator(new IBarcodeGenerator() {

		private BufferedImage getImage(
			BarcodeParameters parameters) {

			if (parameters.getBarcodeType() == null || parameters.getBarcodeValue() == null) {
				return null;
			}

			try {
				Barcode barcode = BarcodeFactory.createEAN128(parameters.getBarcodeValue());
				barcode.setDrawingText(false);
				BarcodeImageHandler.savePNG(barcode, new File("barcode.png"));
				BufferedImage image = ImageIO.read(new File("barcode.png"));
				return image;
			}
			catch (BarcodeException | OutputException | IOException e) {
				throw new RuntimeException(e);
			}
		}

		@Override
		public BufferedImage getBarcodeImage(
			BarcodeParameters parameters) {

			return getImage(parameters);
		}

		@Override
		public BufferedImage getOldBarcodeImage(
			BarcodeParameters parameters) {

			return getImage(parameters);
		}

Hi Kálmán,

Thanks for your inquiry. You can download MergeBarcode_Template.zip from the following link:

Please ZIP your input Word document and Aspose.Words for Java generated output PDF file, upload to dropbox or any other file hosting service and share link here for testing. We will investigate the issue on our end and provide you more information.

Best regards,

In simple test cases the Barbecue + Aspose.words works fine.
Attached the test project (Eclipse Maven) where there is a problem. The test.pdf should contain two barcode under “Vonalkód”, but it is empty.

aspose.barcode.zip (85.8 KB)

Hi Kálmán,

Thanks for your inquiry. After an initial test with Aspose.Words for Java 17.6, we were unable to reproduce this issue on our end during executing your code. Please see:
https://www.dropbox.com/s/rg3g10hi6qxzbdi/awjava-17.6.pdf?dl=0.

We would suggest you please upgrade to the latest version of Aspose.Words for Java. You can download it from the following link:

Download latest version of Aspose.Words for Java.

Hope, this helps.

Best regards,

It works perfectly with 17.6. Thank you!