Java Printing Issue with Media Size

451 Views Asked by At

I will print labels over jasper-report on a brother QL-700. My problem is that java tells the printer driver the wrong label format ☹ - When I use the printer dialog in Java, I can’t found the correct page size in the drop down list - The page is available when I go under the windows driver settings / properties (62mm) but in java the page size is missing ☹ - When I try to define the MediaSize it does not work … - I funny behavior is when I define first a DIN_A4 page and then a custom page the printer dialog will show the custom page but print a DIN_A4 …

The label size is 62x20mm the printer dialog shows the page size as 17x54mm (from find media? Is the nearest size to 62x20) => But the printer will not print if the size is not 62mm … ☹ My code snippet:

// Fill report
JasperPrint jasperPrint = null;
try {
    jasperPrint = report.fillIt(jasperReport, (HashMap<String,Object>) parameters, dataSource2);
} catch (JRException e1) {

    //e1.printStackTrace();
}
logger.info("Fill report");
logger.info(jasperPrint.toString());

logger.info("start print Report");

logger.info("h=" + jasperPrint.getPageHeight() + " w=" +jasperPrint.getPageWidth());
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
// printRequestAttributeSet.add(MediaSizeName.ISO_A4);
printRequestAttributeSet.add(new MediaPrintableArea(0, 0, 62, 4, MediaPrintableArea.MM));
printRequestAttributeSet.add(new Copies(1));


PrintServiceAttributeSet printServiceAttributeSet = new HashPrintServiceAttributeSet();

//PrintServiceAttributeSet .add(new MediaPrintableArea(0, 0, 62, 4, MediaPrintableArea.MM));
JRPrintServiceExporter exporter = new JRPrintServiceExporter();



exporter.setExporterInput(new SimpleExporterInput(jasperPrint));
SimplePrintServiceExporterConfiguration expConfig = new SimplePrintServiceExporterConfiguration();

PrintService service = Printerlookup.getPrintservice(printername, Boolean.TRUE, Boolean.TRUE);
expConfig.setPrintService(service);


//exporter.setParameter(JRExporterParameter.PAGE_INDEX, pageIndex);
//exporter.setParameter(JRExporterParameter.START_PAGE_INDEX, pageStartIndex);
//exporter.setParameter(JRExporterParameter.END_PAGE_INDEX, pageEndIndex);

expConfig.setPrintRequestAttributeSet(printRequestAttributeSet);
expConfig.setPrintServiceAttributeSet(printServiceAttributeSet);

//  expConfig.setDisplayPageDialog(Boolean.TRUE);
// expConfig.setDisplayPrintDialog(Boolean.TRUE);
expConfig.setDisplayPrintDialog(Boolean.FALSE);

exporter.setConfiguration(expConfig);
try {
    exporter.exportReport();
} catch (JRException e2) {
    // TODO Auto-generated catch block
    e2.printStackTrace();
}



logger.info("Finished Test Print ");

Have anybody any idea what I do wrong? Thanks!

0

There are 0 best solutions below