Jump to content
Changes to the Jaspersoft community edition download ×

printing labels with jasperreports


Recommended Posts

By: Jeremy Jones - whiskaz

printing labels with jasperreports

2003-02-14 10:38

Is it possible to print labels using jasperreports? e.g. mailing labels, etc... I'm guessing that it's all in how you format the document but I'm just looking for someone that's actually done it. If you can't do it using JasperReports, is there another Java-based, server side solution?

 

Thanks for the info.

 

-Jeremy

 

 

 

 

By: Teodor Danciu - teodord

RE: printing labels with jasperreports

2003-05-10 03:28

 

Hi,

 

I suppose this goes down to setting the correct

page size to correspond to the label size.

 

If there is someone there who achieved this,

please share your experience with us.

 

This is related:

https://sourceforge.net/forum/forum.php?thread_id=863221&forum_id=113529

 

Thank you,

Teodor

 

 

 

 

 

By: Enrico Goosen - enricogoosen

RE: printing labels with jasperreports

2003-09-02 01:18

Hi,

 

I'm using JasperReports to print labels. Here's my code:

public class LabelGenerator {

 

Collection students;

 

public LabelGenerator(Collection students) {

this.students = students;

}

 

public JasperDesign getJasperDesign() throws JRException{

//JasperDesign

JasperDesign jasperDesign = new JasperDesign();

jasperDesign.setName("AddressLabelDesign");

jasperDesign.setPageWidth(595);

jasperDesign.setPageHeight(842);

jasperDesign.setColumnCount(2);

jasperDesign.setColumnWidth(265);

jasperDesign.setColumnSpacing(0);

jasperDesign.setLeftMargin(40);

jasperDesign.setRightMargin(25);

jasperDesign.setTopMargin(0);

jasperDesign.setBottomMargin(0);

 

//Fonts

JRDesignReportFont normalFont = new JRDesignReportFont();

normalFont.setName("Arial_Normal");

normalFont.setDefault(true);

normalFont.setFontName("Arial");

normalFont.setSize(10);

normalFont.setPdfFontName("Helvetica");

normalFont.setPdfEncoding("Cp1252");

normalFont.setPdfEmbedded(false);

jasperDesign.addFont(normalFont);

 

//Fields

JRDesignField field = new JRDesignField();

field = new JRDesignField();

field.setName("firstnames");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

field = new JRDesignField();

field.setName("surname");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

field = new JRDesignField();

field.setName("address1");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

field = new JRDesignField();

field.setName("address2");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

field = new JRDesignField();

field.setName("city");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

field = new JRDesignField();

field.setName("postcode");

field.setValueClass(java.lang.String.class);

jasperDesign.addField(field);

 

//Detail

JRDesignBand band = new JRDesignBand();

band.setHeight(105);

 

JRDesignTextField textField = new JRDesignTextField();

textField.setX(10);

textField.setY(15);

textField.setWidth(265);

textField.setHeight(15);

textField.setFont(normalFont);

JRDesignExpression expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{firstnames} + " " + $F{surname}");

textField.setExpression(expression);

band.addElement(textField);

 

textField = new JRDesignTextField();

textField.setBlankWhenNull(true);

textField.setX(10);

textField.setY(30);

textField.setWidth(265);

textField.setHeight(15);

textField.setFont(normalFont);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{address1}");

textField.setExpression(expression);

band.addElement(textField);

 

textField = new JRDesignTextField();

textField.setBlankWhenNull(true);

textField.setX(10);

textField.setY(45);

textField.setWidth(265);

textField.setHeight(15);

textField.setFont(normalFont);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{address2}");

textField.setExpression(expression);

band.addElement(textField);

 

textField = new JRDesignTextField();

textField.setBlankWhenNull(true);

textField.setX(10);

textField.setY(60);

textField.setWidth(265);

textField.setHeight(15);

textField.setFont(normalFont);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{city}");

textField.setExpression(expression);

band.addElement(textField);

 

textField = new JRDesignTextField();

textField.setBlankWhenNull(true);

textField.setX(10);

textField.setY(75);

textField.setWidth(265);

textField.setHeight(15);

textField.setFont(normalFont);

expression = new JRDesignExpression();

expression.setValueClass(java.lang.String.class);

expression.setText("$F{postcode}");

textField.setExpression(expression);

band.addElement(textField);

 

jasperDesign.setDetail(band);

 

//Column footer

band = new JRDesignBand();

jasperDesign.setColumnFooter(band);

 

//Page footer

band = new JRDesignBand();

jasperDesign.setPageFooter(band);

 

//Summary

band = new JRDesignBand();

jasperDesign.setSummary(band);

 

return jasperDesign;

}

 

public JasperReport getJasperReport(){

try{

return JasperCompileManager.compileReport(getJasperDesign());

}catch (dori.jasper.engine.JRException jre){

jre.printStackTrace();

}

return null;

}

 

public JasperPrint getJasperPrint(){

try{

return JasperFillManager.fillReport(getJasperReport(), new HashMap(), new JRBeanCollectionDataSource(students));

}catch (dori.jasper.engine.JRException jre){

jre.printStackTrace();

}

return null;

}

 

public void generateLabels(){

try{

JasperViewer viewer = new JasperViewer(getJasperPrint(), false);

viewer.setTitle("ICDL System Administration: Address labels");

viewer.show();

}catch (dori.jasper.engine.JRException jre){

jre.printStackTrace();

}

}

}

 

I'm using continuous paper labels, with 2 columns and 8 labels per column (ie. 16 labels per sheet).

 

I'm using an Epson LX-300+ printer, and the character quality is shite. Can anyone help me in this regard?

 

Enrico

Link to comment
Share on other sites

  • 9 months later...
  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...