By: Oleg - oleg_vn
How to Print Lanscape Report
2002-12-17 06:12
My code:
--------------
PrintService[] services = PrinterJob.lookupPrintServices();
for (int i = 0; i < services.length; i++) {
jComboBoxPrinter.addItem(services.getName());
}
...
PageRanges pRanges= new PageRanges("2,4,6");
try {
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(MediaSizeName.ISO_A4);
printRequestAttributeSet.add(pRanges);
if (jasperPrint.getOrientation() == JRReport.ORIENTATION_LANDSCAPE) {
printRequestAttributeSet.add( OrientationRequested.LANDSCAPE );
} else {
printRequestAttributeSet.add( OrientationRequested.PORTRAIT );
}
PrintServiceAttributeSet printServiceAttributeSet =
services[jComboBoxPrinter.getSelectedIndex()].getAttributes();
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);
exporter.exportReport();
}
catch (JRException ex)
{
ex.printStackTrace();
}
catch (Exception ex)
{
ex.printStackTrace();
}
-------------------
All fine, but printed only part of page. (Left margin = 80.75 cm)
I`m added this :
printRequestAttributeSet.add(
new MediaPrintableArea(
0f,
0f,
(float)jasperPrint.getPageWidth() / 72f,
(float)jasperPrint.getPageHeight() / 72f,
MediaPrintableArea.INCH )
);
and catch Exception :
"No suitable print service found."
Help me!
Oleg
How to Print Lanscape Report
2002-12-17 06:12
My code:
--------------
PrintService[] services = PrinterJob.lookupPrintServices();
for (int i = 0; i < services.length; i++) {
jComboBoxPrinter.addItem(services.getName());
}
...
PageRanges pRanges= new PageRanges("2,4,6");
try {
PrintRequestAttributeSet printRequestAttributeSet = new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(MediaSizeName.ISO_A4);
printRequestAttributeSet.add(pRanges);
if (jasperPrint.getOrientation() == JRReport.ORIENTATION_LANDSCAPE) {
printRequestAttributeSet.add( OrientationRequested.LANDSCAPE );
} else {
printRequestAttributeSet.add( OrientationRequested.PORTRAIT );
}
PrintServiceAttributeSet printServiceAttributeSet =
services[jComboBoxPrinter.getSelectedIndex()].getAttributes();
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);
exporter.exportReport();
}
catch (JRException ex)
{
ex.printStackTrace();
}
catch (Exception ex)
{
ex.printStackTrace();
}
-------------------
All fine, but printed only part of page. (Left margin = 80.75 cm)
I`m added this :
printRequestAttributeSet.add(
new MediaPrintableArea(
0f,
0f,
(float)jasperPrint.getPageWidth() / 72f,
(float)jasperPrint.getPageHeight() / 72f,
MediaPrintableArea.INCH )
);
and catch Exception :
"No suitable print service found."
Help me!
Oleg
0 Answers:
No answers yet