javax.print setting attributes
There's no section for javax.print so -
I have a program for printing a pdf file that was generated using the iText 2 package.
The file is created as an A4 document.
The program is able to load the file and send the print job - it reaches the printer, but on the printer the control panel prompts the user to load A4, Plain Paper. The print job will come out if the user presses "OK" on the printer to override and print to whatever paper is loaded.
I need it to print directly without user intervention, as the same file prints directly from Adobe Reader without this problem.
I also need it to print 2 copies and it only prints one.
Here is the code for creating the print job:
Code :
PrintRequestAttributeSet preqats = new HashPrintRequestAttributeSet();
preqats.add(new Copies(2));
preqats.add(MediaTray.MAIN);
preqats.add(MediaSizeName.ISO_A4);
job.print(doc, preqats);
I am running this on a Windows 7 32-bit machine.
Printer model is HP LJ P3015.
The printer is hosted on a Windows Server 2003 machine.
I have set the printer defaults to:
Paper size = A4
Paper source = Auto
Paper Type = Unspecified
In the printer setup I have selected the paper size and types to Auto and unspecified.
So in PrintRequestAttributes or DocPrintJobAttributes how do I make sure
my print job is not trying to override the default paper type?
Re: javax.print setting attributes
What if you do not include the line that says:
Code java:
preqats.add(MediaSizeName.ISO_A4);
I'm just guessing, but maybe it thinks you are trying to override the paper type simply because you specified the paper type. If you don't specify the printing type (and it still works), it should logically use the printer's default paper type.
Give it a try and tell me what happens.
EDIT: I suspect this is happening. If you read the API for MediaSizeName (MediaSizeName (Java Platform SE 6)), it reads:
Quote:
This attribute can be used instead of specifying MediaName or MediaTray.
Since you are specifying the MediaTray, you should not have to specify the MediaSizeName.
Re: javax.print setting attributes
Hi aussiemcgr,
I have tried a few variations, with and without the attributes:
Code :
PrintRequestAttributeSet preqats = new HashPrintRequestAttributeSet();
preqats.add(new Copies(2));
// Media Tray and MediaSizeName attributes are disabled to use the printer defaults
// preqats.add(MediaTray.MAIN);
//preqats.add(MediaSizeName.ISO_A4);
Also tried adding
Code :
preqats.add(MediaName.ISO_A4_WHITE);
Also changed the paper type in the printer setup, so if the printer thinks I'm sending a plain paper print request, and it has plain paper in stock, it should go ahead and print.
No success!
If I open a standard cross platform printdialog from ServiceUI.printDialog there are no options for paper type.
I do get these options in the Windows native dialog if I print from Adobe Reader. But I haven't seen any info on using platform native dialogs from javax.print, only from java.awt.print.
Many thanks