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

How to Print Lanscape Report


Recommended Posts

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

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