0

I had a piece of code which was working in java version 1.5 but when i recently updated the java version to 1.6, the application was generating unscannable barcodes.

When compared with previous version, the barcodes were slightly different. Thickness of certain lines also changed

Please help

Code Below::

    String str = (String)TSFDataChannel.getValue(httpservletrequest,"BC");

    File file = new File("mybarcode_"+Helpers.stripGarbage(str)+".png");
    OutputStream out = new FileOutputStream(file);

    Barcode barcode;
    try {

        Code128Bean bean = new Code128Bean();

        final int dpi = 500;

        //Configure the barcode generator
        bean.setModuleWidth(UnitConv.in2mm(1.0f / dpi)); //makes the narrow bar
        bean.setFontSize(0); //width exactly one pixel

        bean.doQuietZone(false);
        //bean.setVerticalQuietZone(UnitConv.pt2mm(3)); 
        bean.setHeight(1.5); 
        BitmapCanvasProvider canvas = new BitmapCanvasProvider(
        out,"image/png", dpi, BufferedImage.TYPE_BYTE_BINARY, true, 0); 

        //Generate the barcode
        bean.generateBarcode(canvas, str);

        //Signal end of generation
        canvas.finish();

        httpservletresponse.setContentType("APPLICATION/OCTET-STREAM");
        String disHeader = "Attachment;Filename=mybarcode_"+str+".png" ;
        httpservletresponse.setHeader("Content-Disposition", disHeader);

        FileInputStream fileInputStream = new FileInputStream(file);
        int i;
        while ((i=fileInputStream.read())!=-1)
        {
            httpservletresponse.getOutputStream().write(i);
        }

        httpservletresponse.getOutputStream().flush();
        httpservletresponse.getOutputStream().close();
        fileInputStream.close();

    } catch (Exception e1) {
        e1.printStackTrace();
    } finally{
        file.delete();
        out.close();
    }
fvu
  • 32,488
  • 6
  • 61
  • 79
Sumit
  • 39
  • 1
  • 5
  • `Content-Type` is case sensitive. It's not `APPLICATION/OCTET-STREAM` but `application/octect-stream`. – Buhake Sindi Apr 30 '14 at 11:38
  • I think that the `Code128Bean` object comes from the [Barcode4J project](http://barcode4j.sourceforge.net). Are you sure you're using a reasonably recent version of that library? – fvu Apr 30 '14 at 11:48
  • @BuhakeSindi this is a working piece of code, so i dont think case sensitivity should be a the main issue here, although i will make a note of it. – Sumit Apr 30 '14 at 11:59
  • @fvu I am not sure if this is indeed the latest version, could you tell me how can i check that.Could this be the reason ? – Sumit Apr 30 '14 at 12:00
  • @Sumit see the link to the project page embedded in my comment. You'll find all versions of the software there, the complete changelog and more. – fvu Apr 30 '14 at 12:08
  • @Sumit, I took it under assumption that this runs well on IE. Other browsers might be affected by it???? – Buhake Sindi Apr 30 '14 at 12:10
  • @BuhakeSindi it is working well in firefox as well. – Sumit Apr 30 '14 at 13:18
  • @fvu i am using ver 2.0 which is a stable release. As per the change log, i dont see anything based on jdk version 1.6 or 1.7. So ideally this should not be causing the issue – Sumit Apr 30 '14 at 13:20
  • @Sumit Indeed. Please note that I added the "barcode4j" tag to the question. – fvu Apr 30 '14 at 15:10

0 Answers0