BarCode generated image is blank

Hello,

We’re using Aspose BarCode to generate BarCode images from data that is being extracted from XML documents.
When we run on the BarCode 8.8.0 version our code is working just fine.
We bought a new license to upgrade to 17.10, and now our code suddenly produces empty images in our documents.
There’s no errors being thrown at all, and the code compiles without problems.

This is the snippet I am using to generate a BarCode based on parameters and return the raw image data, which we assign to image shapes:

private static BufferedImage generateBarcode(SymbologyEncodeType type, float width, float height, String value) {
	BarCodeBuilder builder = new BarCodeBuilder(value, type);
	
	builder.setImageHeight(height);
	builder.setImageWidth(width);
	
	return builder.getOnlyBarCodeImage();
}

The returned image is then assigned to a Shape object.
So am I missing something? Cause every word document or PDF generated with this only has blank images, whereas this worked fine before.

This is an example output: output.pdf (36.6 KB)

@Olivar,

We have tried to reproduce the issue at our end and are unable to notice any issue. The barcode image was generated successfully and integrated into the PDF. We have used the latest version of Aspose.BarCode and Aspose.Pdf. Sample code snippet that we used is given below for your reference. Please try with latest versions of the APIs and share your feedback.

CODE:

Aspose.BarCode.BarCodeBuilder builder = new Aspose.BarCode.BarCodeBuilder();
        builder.CodeText = "1234567";
        builder.EncodeType = Aspose.BarCode.Generation.EncodeTypes.Code128;

        System.IO.MemoryStream ms = new System.IO.MemoryStream();
        builder.BarCodeImage.Save(ms, System.Drawing.Imaging.ImageFormat.Bmp);

        Aspose.Pdf.License _lic = new Aspose.Pdf.License();
        _lic.SetLicense(@"..\lic\Aspose.Total.lic");

        Aspose.Pdf.Generator.Pdf pdf1 = new Aspose.Pdf.Generator.Pdf();
        Aspose.Pdf.Generator.Section sec1 = pdf1.Sections.Add();

        Aspose.Pdf.Generator.Image image1 = new Aspose.Pdf.Generator.Image(sec1);

        image1.ImageInfo.ImageFileType = Aspose.Pdf.Generator.ImageFileType.MemoryBmp;
        image1.ImageInfo.OpenType = Aspose.Pdf.Generator.ImageOpenType.Memory;
        image1.ImageScale = 0.5F;

        System.IO.BinaryReader reader = new System.IO.BinaryReader(ms);
        ms.Position = 0;
        image1.ImageInfo.MemoryData = reader.ReadBytes((int)ms.Length);

        sec1.Paragraphs.Add(image1);
        pdf1.Save(@"MyBarCode_out.pdf");

MyBarCode_out.pdf (7.8 KB)

That’s a slightly different approach then I am working with.
I have a document Shape, on which I want to assign the image data: shape.getImageData().setImage(myImage)

Where the myImage is the return value of the function below:

	private static BufferedImage generateBarcode(SymbologyEncodeType type, float width, float height, String value) {
	BarCodeBuilder builder = new BarCodeBuilder();
	
	builder.setCodeText(value);
	builder.setEncodeType(type);
	builder.setImageWidth(width);
	builder.setImageHeight(height);
	
	return builder.getOnlyBarCodeImage();
}

And the PDF gets generated, but with the empty images.
I’ve used debugger and everything, and I’m hitting the code points, so I know it’s being called.
Either there’s a problem with the Java API or something else is missing, and I’m not getting any sensible output whatsoever telling me what’s wrong.

@Olivar,

Please share which JDK version are you using.

Aspose.Total 17.10 (not everything, we use Words, Cells, PDF, Shapes and BarCode)
Java Oracle JDK 1.8.0_152

@Olivar,

Thank you for details. We have used the following code snippet to generate the barcode image, build the word document and then save it as PDF file. We used the latest versions of the APIs. We are able to generate the required PDF successfully having proper barcode image in it.

CODE:

  com.aspose.barcode.BarCodeBuilder builder = new com.aspose.barcode.BarCodeBuilder();
    builder.setCodeText("9223372036854775804");
    builder.setEncodeType(com.aspose.barcode.EncodeTypes.CODE_39_EXTENDED);

    // Creating memory stream and Saving barcode image to memory stream
    java.io.ByteArrayOutputStream outStream = new java.io.ByteArrayOutputStream();
    builder.save(outStream, com.aspose.barcode.BarCodeImageFormat.Jpeg);
    
    com.aspose.words.License license = new com.aspose.words.License();
    license.setLicense("Aspose.Total.Java.lic");
    
    com.aspose.words.Document doc = new com.aspose.words.Document();
    com.aspose.words.DocumentBuilder docBuilder = new com.aspose.words.DocumentBuilder(doc);

    java.io.InputStream is1 = new java.io.ByteArrayInputStream(outStream.toByteArray());

    docBuilder.insertImage(is1);
    
    String strWordFile = "barcode_doc.pdf";
    doc.save(strWordFile, com.aspose.words.SaveFormat.PDF); 

docBuilder.insertImage function it will return a com.aspose.words.Shape which can be used further. Resultant PDF file is attached for your reference.barcode_doc.pdf (16.2 KB)

Got it working as well now.
Someone added some obscure code that skipped a crucial call to the configuration :confused:
Apologies for this, but it works as expected now.

@Olivar,

It is good to know that the issue has been resolved and things are now working at your end. Thank you for update.