• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

Print Barcode in Jasper Reports API (Java)

 
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Does anyone know how to print barcode with jasperreports-6.3.0 library? All the examples I've seen until now , they contain automization generators for barcode such as onbarcode, etc. Although in that library exist net.sf.jasperreports.components.barcode4j.Code128Component.
In my code I choose the field from database dynamically with that :
      JRDesignTextField designField = new JRDesignTextField();
      designField.setX(0);
      designField.setY(0);
      designField.setWidth(bar_width);
      designField.setHeight(bar_height);
      JRDesignExpression exp = new JRDesignExpression();
      exp.setText("$F{PatientID}");
      designField.setExpression(exp);
      detail_band.addElement(designField);
      ((JRDesignSection) jasperDesign.getDetailSection()).addBand(detail_band);
It shows the IDs like : 103657 , 103658.... But I can not find the way to make them barcodes with jasper reports.
Does anyone can help here?
I try this without to give me another result :

      JRDesignComponentElement barCode = new JRDesignComponentElement();
      barCode.setX(0);
      barCode.setY(0);
      barCode.setHeight(30);
      barCode.setWidth(60);
      ((JRDesignSection) jasperDesign.getDetailSection()).addBand(detail_band);
     
     
       StandardBarbecueComponent stdBBQComponent = new StandardBarbecueComponent();
       stdBBQComponent.setType("Code128");
       stdBBQComponent.setDrawText(false);
       stdBBQComponent.setChecksumRequired(false);
       stdBBQComponent.setBarHeight(bar_height);
       stdBBQComponent.setEvaluationTimeValue(EvaluationTimeEnum.REPORT);
       ((JRDesignSection) jasperDesign.getDetailSection()).addBand(detail_band);
       
       JRDesignExpression designExpression = new JRDesignExpression();
       designExpression.setText("$F{PatientID}");
       stdBBQComponent.setCodeExpression(designExpression);
       barCode.setComponent(stdBBQComponent);
       ((JRDesignSection) jasperDesign.getDetailSection()).addBand(detail_band);
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Δήμητρα,
My solution is just to add a call to the method JRDesignComponentElement.setComponentKey, passing name, prefix and namespace of the barcode component.
Here is my code, it works fine !


 
reply
    Bookmark Topic Watch Topic
  • New Topic