Jump to content
We've recently updated our Privacy Statement, available here ×

JRPrintServiceExporter vs. custom sized label


Recommended Posts

By: quirin - mq25046

JRPrintServiceExporter vs. custom sized label

2006-06-21 02:59

Does anybody use the JRPrintServiceExporter to print custom-sized labels without opening the "display print dialog"?

 

Since I use jasper report's JRPrintServiceExporter, instead of directly accessing the jdk's print api, I have problems to print custom-sized labels.

Either labels are only half printed or printing completly fails on Zebra (105SL) label printers.

 

I have to say that Zebra printers are very sensitive in getting the correct label's size. If the printjob's submitted size doesn't match the printer's deposited label size, the Zebra printer just will consume the generated printjob but doesn't print at all.

 

It seems the JRPrintServiceExporter doesn't (correctly) set the PageFormat to jasperprint's dimensions and thus causes the trouble described above.

 

I've added some log statements to the JRPrintServiceExporter:

 

public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException

{

System.out.println("pageformat's height: " + pageFormat.getHeight());

System.out.println("pageformat's width: " + pageFormat.getWidth());

...

}

 

result: the pageformat's dimensions are different from my label's dimensions.

-> my label's dimensions 289x241 (WxH) points

-> log from pageformat 288x432 (WxH) points

 

Anybody there who made the same experience or who can help ?

 

Best regards,

Quirin

 

=============================================================================

Here's a short example how I try to print:

 

import java.io.InputStream;

import java.util.HashMap;

import java.util.Map;

 

import javax.print.attribute.HashPrintRequestAttributeSet;

import javax.print.attribute.HashPrintServiceAttributeSet;

import javax.print.attribute.PrintRequestAttributeSet;

import javax.print.attribute.PrintServiceAttributeSet;

import javax.print.attribute.standard.Copies;

import javax.print.attribute.standard.PrinterName;

 

import net.sf.jasperreports.engine.JREmptyDataSource;

import net.sf.jasperreports.engine.JRException;

import net.sf.jasperreports.engine.JRExporterParameter;

import net.sf.jasperreports.engine.JasperCompileManager;

import net.sf.jasperreports.engine.JasperFillManager;

import net.sf.jasperreports.engine.JasperPrint;

import net.sf.jasperreports.engine.JasperPrintManager;

import net.sf.jasperreports.engine.JasperReport;

import net.sf.jasperreports.engine.export.JRPrintServiceExporter;

import net.sf.jasperreports.engine.export.JRPrintServiceExporterParameter;

 

public class PrintApp

{

public static void main(String[] args) throws Exception

{

PrintApp app = new PrintApp();

app.testPrinting();

}

 

private void testPrinting() throws JRException

{

System.out.println("get report template");

InputStream templateAsStream = ClassLoader.getSystemResourceAsStream("myLabel.jrxml");

 

System.out.println("compile report");

JasperReport jasperReport = JasperCompileManager.compileReport(templateAsStream);

 

// submit parameters

Map parameters = new HashMap();

parameters.put("param1", "jasper report ...");

parameters.put("param2", "...rules");

 

System.out.println("fill the compiled template");

JasperPrint jasperPrint = JasperFillManager.fillReport(jasperReport, parameters, new JREmptyDataSource());

 

PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();

PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();

 

//printServiceAttributeSet.add(MediaSizeName.ISO_A4);

printServiceAttributeSet.add(new PrinterName("Zebra105SL-1", null));

printRequestAttributeSet.add(new Copies(1));

 

JRPrintServiceExporter exporter = new JRPrintServiceExporter();

 

exporter.setParameter(JRExporterParameter.JASPER_PRINT, jasperPrint);

exporter.setParameter(JRPrintServiceExporterParameter.PRINT_REQUEST_ATTRIBUTE_SET, printRequestAttributeSet);

exporter.setParameter(JRPrintServiceExporterParameter.PRINT_SERVICE_ATTRIBUTE_SET, printServiceAttributeSet);

exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG, Boolean.FALSE);

exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG, Boolean.FALSE);

 

System.out.println("export to printer");

 

exporter.exportReport();

 

// JasperPrintManager.printReport(jasperPrint, false);

}

}

 

 

By: quirin - mq25046

RE: JRPrintServiceExporter vs. custom sized l

2006-06-21 06:31

I forgot to mention I'm using jasperreports 1.2.3 on jdk 1.4.2 and windows xp sp2

Link to comment
Share on other sites

  • Replies 0
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

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...