Title: JRPrintServiceExporter vs. custom sized label

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 ?

Btw: I'm using jasperreports 1.2.3 on jdk 1.4.2 and windows xp sp2. (Also tested with jasperreports 1.2.4 - but same result as mentioned above)
 
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); 

}
<<myLabel.jrxml>>
       

 


Attachment: myLabel.jrxml
Description: Binary data

Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
jasperreports-questions mailing list
jasperreports-questions@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jasperreports-questions

Reply via email to