Skip to main content

How to enable printer range selection in printer Dialog?

6 replies [Last post]
jessycute
Offline
Joined: 2005-01-13
Points: 0

I try to do the printer setup, when I do
Code:

:

job.setPageable (book);
if (job.printDialog ()) {
try {
job.print ();
}
catch (PrinterException ex) {
ex.printStackTrace ();
}
}

:
note: job is PrinterJob.

The printer setup that shown, it disable the selection mode in printer range. Anyone know how to enable it or do print by text selection (highlight).
Thank you in advance.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
stanislavl
Offline
Joined: 2003-06-17
Points: 0

Try to use
printDialog(PrintRequestAttributeSet attributes) method with attributes. Also Pageable must be set to the PrinterJob with specified amount of pages.

regards,
Stas

jessycute
Offline
Joined: 2005-01-13
Points: 0

Thanks. yes, I already try it with PrintRequestAttributeSet. But it will show the printer setup with java version not the native version.

Anyway,I found the solution to do follow this.

JobAttributes jobAttributes = new JobAttributes();
jobAttributes.setDialog(JobAttributes.DialogType.NATIVE);
Frame dummyFrame = new Frame();
PrintJob pJobDialog = Toolkit.getDefaultToolkit().getPrintJob(dummyFrame, "Printtest", jobAttributes, null);

This code will show you the printer setup, but the problem is I can not disable some selection. - -!

Any one know the way. Thanks.

leo_test
Offline
Joined: 2004-04-27
Points: 0

In your sample, I do not see, how you follow what posted by stanislavl. You do not use the PrintRequestAttributeSet neither use the setDialog them. As well take into account, that the job.print has a version with the print-Dialog supported (look into the super class, how they use it). And last but not least note there is a signifant difference between the dialogs, i.e. using PageFormat or with PrintRequestAttributeSet. Not only the Dialogs, as well the result of Size!

jessycute
Offline
Joined: 2005-01-13
Points: 0

Thanks, I already try follow what posted by stanislavl.
:
//Creates a new attribute set
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
// Prints 5 copies
aset.add(new Copies(5));
// Prints two-sided
aset.add(Sides.DUPLEX);
// Staples the pages
aset.add(Finishings.STAPLE);

printJob.printDialog(aset);
:

But the printer dialog will show in java frame look & feel , not is the native printer dialog.
So, I will try to find out the other way.

amirpat
Offline
Joined: 2005-04-21
Points: 0

I am using custom implementation of Pageable and setting the printer job like this.

print(){
.......
javax.print.attribute.PrintRequestAttributeSet printRequestAttributeSet = new javax.print.attribute.HashPrintRequestAttributeSet( );
PageSettings pageSettings = getPageSettings( );
printRequestAttributeSet.add( pageSettings.getMediaSizeName( ) );
printRequestAttributeSet.add( pageSettings.getMediaPrintableArea( ) );
PrinterJob printerJob = PrinterJob.getPrinterJob();
if(printerJob.printDialog())
try{

printerJob.setJobName(getJobName());
printerJob.setPageable(getPageablePlus());
printerJob.print(printRequestAttributeSet);

}catch(java.awt.print.PrinterException e){
System.out.println("Exception in PrintSupport");
e.printStackTrace( );
}

}

the page range selection is coming disables.
Any tip how to enable that?
I am stuck please help.
Thanks in advance.

navynine
Offline
Joined: 2013-08-06
Points: 0

Hello,

I've encountered with the same problem - in the native print dialog the page range selection was disabled.
The solution was in call

printerJob.setPrintable(printable, pageFormat);

before

printerJob.printDialog();

Maybe it will help for somebody :)