aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Force Landscape Printing Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Force Landscape Printing" Watch "Force Landscape Printing" New topic
Author

Force Landscape Printing

Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 217
I have a printjob set up that is working with one problem.

While the layout is landscape the target printer orientation is portrait by default. The user has to remember to switch it to landscape. Short of generating a reminder message during the print dialog, is there not a way to force the print driver to use landscape rather than the default? TIA.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2417
    
  50
This is not an area I'm particularly experienced in so the following advice may or may not be useful.
Have you tried using the printDialog(PrintRequestAttributeSet attribs) method adding the OrientationRequested.LANDSCAPE attribute to the attribute set?
Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 217
Thanks for the reply. I have not since I was not aware of it. I'll have to read up on it.
Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 217
I am not having much success getting what I need. I was successful in implementing PageRequestAttributeSet. The page setup pops up with landscape selected, although I don't know why I need that since it is now selected. However, that does not help since the print services apparently ignore that. I then tried using PrintService and created a combobox so the user can select the printer in my application. Again that all works and the correct printer is selected when the print dialog comes up. Unfortunately the orientation is still the default rather than landscape. I now have 2 issues to over come. The first is to eliminate the page setup popup which is not needed even if it worked. The second is to set landscape orientation. FWIW, here is the new print class:

This is how I get the selected printer service:
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2417
    
  50
It may be that your printer ignores the orientation setting. If you get the PrintService object it has some methods for querying if the printer supports certain attributes and values. It may be worth checking to see if your print does support this although I would be surprised if any printer that can print landscape does not support the setting.
Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 217
Thanks and I agree that it is unlikely since I have several different printers and all (mis)behave the same.
Tony Docherty
Bartender

Joined: Aug 07, 2007
Posts: 2417
    
  50
Yes, that makes it even more unlikely then.

I think I may have spotted your error, when you call setPrintable() I think you may need to pass the required page format to it as a second parameter, as follows:
Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 217
Bingo!!! That was it. However, I am still getting the print dialog which I neither need nor want. That only started happening when I added the PrintRequestAttributeSet code. Is there a way to eliminate it?
Dennis Putnam
Ranch Hand

Joined: Feb 03, 2012
Posts: 217
Never mind. I got it. The call to pageDialog() was not necessary.
Jay Dilla
Ranch Hand

Joined: Aug 12, 2004
Posts: 201
Is there a way to achieve this without using the Printable interface? Have been stuck on this for a while.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Force Landscape Printing