Free Support Forum - aspose.com

Incorrect code text measurement on linux

Hi All,R-1082503101704_20210409142256.PNG (7.5 KB)
W-1082503101704_20210409135832.PNG (7.2 KB)

Lately I have noticed one strange behavior on databar expended stacked in the barcode API 21.3 java version. The text showing in one row when i run the barcode ap in windows but the same text showing two rows running in docker linux image. pls see my testing code and attached for your investigation the issue may be the similar toBARCODENET-37428 .

	String GTIN1 = "(01)1082503101704";
	int row = 2;
	
	float xdim=0.33f;
	float height=23.43f;
	
	// Generate and save the image to file
	BarcodeGenerator builder = new BarcodeGenerator(EncodeTypes.DATABAR_EXPANDED_STACKED);
	// Set code text
	
	builder.setCodeText(GTIN1);
	builder.getParameters().getBarcode().getDataBar().setRows(row);
	builder.getParameters().setAutoSizeMode(AutoSizeMode.NONE);
	
	builder.getParameters().getBarcode().getCodeTextParameters().getFont().getSize().setMillimeters(80);
	
	builder.getParameters().getBarcode().getXDimension().setMillimeters(xdim);
	builder.getParameters().getBarcode().getBarHeight().setMillimeters(height);
	
	builder.getParameters().getBarcode().getPadding().getLeft().setInches(0);
	builder.getParameters().getBarcode().getPadding().getRight().setInches(0);
	builder.getParameters().getBarcode().getPadding().getTop().setInches(0);
	builder.getParameters().getBarcode().getPadding().getBottom().setInches(0);

	
	builder.getParameters().setResolution(600f);
	
			

	try {
		//ByteArrayOutputStream bye = new ByteArrayOutputStream();
		
		//builder.save(bye, BarCodeImageFormat.PNG);
		
		//BufferedImage newBi = builder.generateBarCodeImage();
	
		
		//builder.save("c:\\temp\\" + row + "_Row_" + "XDIM_" + xdim*1000 + ".png", BarCodeImageFormat.PNG);
		//ImageIO.write(newBi, "svg", new File("c:\\temp\\google-decode.svg"));
		//ImageIO.write(newBi, "png", new File("c:\\temp\\google-decode.png"));
		
		builder.save("c:\\temp\\" + "j1.png", BarCodeImageFormat.PNG);
		//builder.save("c:\\temp\\" + "j1.svg", BarCodeImageFormat.SVG);
	
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}

the Dockerfile is FROM adoptopenjdk:13-jdk-openj9

RUN ln -fs /usr/share/zoneinfo/America/Toronto /etc/localtime &&
apt-get update
&& apt-get upgrade -y
&& apt-get install -y tzdata libsqlite3-0 apt ca-certificates libssl1.1 libcurl4 curl
&& dpkg-reconfigure --frontend noninteractive tzdata
&& apt-get clean
&& rm -rf /var/lib/apt/lists/*

One more question: Do we have any methods to on how to display the text ? for example can we print the text splited by AI to different row?

Thank you in advance for your help.

You can setup Databar row / columns behavior what-you-want style. You need to get access to Databar parameters:

BarcodeGenerator.getParameters().getBarcode().getDataBar()

And setup required row / columns by setColumns / setRows

BarcodeGenerator.getParameters().getBarcode().getCodeTextParameters().setNoWrap

If you want to wrap text on the next line in your way you can use Caption

//hide codetext
BarcodeGenerator.getParameters().getBarcode().getCodeTextParameters().setLocation(CodeLocation.None)
//create caption with line wrap text
BarcodeGenerator.getParameters().getCaptionBelow.setVisible(true)
BarcodeGenerator.getParameters().getCaptionBelow.setText("“123\n345"”)

Thanks you. one question how to get the barcode width in databar expended stacked. I tried the methods it looks not right, how to sent the font size in the new api. i really want to display the text in one row or i can split them to mutiple row nicely

int x = builder.getParameters().getBarcode().getQuietZonesWidthInXDim();
int y = builder.getParameters().getBarcode().getCalculatedBarCodeWidth();|

Thanks,

You can call BarcodeGenerator.generateBarCodeImage() and measure image width.