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

Choose Printer


Realshit

Recommended Posts

Hi.

I´m trying to print a report, and when I choose the default printer, it works fine.

Now, I want to let the user choose the printer, and I don´t know how do it.

 

I´m doing the printing like this

JRExporter exporter = new JRPrintServiceExporter();
exporter.setParameter(JRExporterParameter.JASPER_PRINT, jPrint);
exporter.setParameter(JRPrintServiceExporterParameter.
PRINT_SERVICE_ATTRIBUTE_SET,
service.getAttributes());
exporter.setParameter(JRPrintServiceExporterParameter.
DISPLAY_PAGE_DIALOG, Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.
DISPLAY_PRINT_DIALOG, Boolean.FALSE);

exporter.exportReport();

 

Then, I need a PrintService (service), but with Java, when I open the standard dialog to choose printer (like this)

PrintJob miPrintJob = frame.getToolkit().getPrintJob( frame,"Select Printer",null );

I only can get a graphics, not a PrintService, and I need this PrintService.

 

Can you help me ??

 

Thanks in advance.

Post edited by: Realshit, at: 2007/01/23 12:59

Link to comment
Share on other sites

  • 2 weeks later...
  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

i also had that problem and for me, it worked like this:

 

Code:

PrinterJob job = PrinterJob.getPrinterJob();
PrintService service = job.getPrintService();
PrintRequestAttributeSet printRequestAttributeSet =
new HashPrintRequestAttributeSet();
printRequestAttributeSet.add(MediaSizeName.ISO_A4);
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,
service.getAttributes());
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PAGE_DIALOG,
Boolean.FALSE);
exporter.setParameter(JRPrintServiceExporterParameter.DISPLAY_PRINT_DIALOG,
Boolean.TRUE);
exporter.exportReport();
Link to comment
Share on other sites

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