It’s possible to use a barcode EAN-128-C in a reports add-on of jmix 1.5 ?
Hi, any news about this ? How to generate a barcode into a report ?
Thanks,
Jasper reports and output to a pdf is the way i would do jt
Hi Eduardo, thanks in advance. My question is, can we insert an external image in a report generated with YARG ?
Thanks,
Hello @fdomenechm,
You can use a barcode in a report, you need to create a report with an image format for the entity field.
Docs: Report Parameters and Field Formatters :: Jmix Documentation
I created a demo project that generates a barcode and saves it in entity.
BarcodeEntityEdit:
@Autowired
private FileStorage fileStorage;
@Subscribe(target = Target.DATA_CONTEXT)
public void onPreCommit(final DataContext.PreCommitEvent event) throws Exception {
BarcodeEntity barcodeEntity = getEditedEntity();
InputStream inputStream = generateEAN13File(barcodeEntity.getBarcodeText());
FileRef fileRef = fileStorage.saveStream("barcode.jpg", inputStream);
barcodeEntity.setBarcode(fileRef);
}
public InputStream generateEAN13File(String barcodeText) throws Exception {
Code128Writer barcodeWriter = new Code128Writer();
BitMatrix bitMatrix = barcodeWriter.encode(barcodeText, BarcodeFormat.CODE_128, 300, 150);
BufferedImage bufferedImage = MatrixToImageWriter.toBufferedImage(bitMatrix);
ByteArrayOutputStream os = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, "jpeg", os);
return new ByteArrayInputStream(os.toByteArray());
}
Next, a report is generated based on the entity.
And to correctly display the barcode in the report, a formatter is used.
Report:
Demo project:
jmix-barcode-report.zip (107.1 KB)
Regards,
Nikita