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

Free Support Forum - aspose.com

How to read barcode from specific page using java

Hi,

I am wondering is there anyway to read barcode from specific page in pdf ? always do we need scan all the pages ?

Please point me to code snippet to read barcode image from specific page in pdf document.

Requirement : We need to read barcode image from specific page in pdf document.

@senthil125,

This is to update you that there is no need to iterate through all pages inside a PDF file. You may use following code snippet to read barcode from specific page in PDF file:

CODE:

    com.aspose.pdf.Document pdfDocument = new com.aspose.pdf.Document("sample.pdf");
    int pageCount = pdfDocument.getPages().size();
    
    java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream();
    com.aspose.pdf.devices.Resolution resolution = new com.aspose.pdf.devices.Resolution(300);
    
    com.aspose.pdf.devices.PngDevice pngDevice = new com.aspose.pdf.devices.PngDevice(resolution);
    pngDevice.process(pdfDocument.getPages().get_Item(pageCount - 2), outputStream);
    
    java.io.ByteArrayInputStream inputStream = new java.io.ByteArrayInputStream (outputStream.toByteArray());
    com.aspose.barcode.barcoderecognition.BarCodeReader reader = new com.aspose.barcode.barcoderecognition.BarCodeReader(inputStream);
        
    while (reader.read())
    {
        System.out.println("codetext: " + reader.getCodeText());
    }