File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Force Landscape Printing

 
Dennis Putnam
Ranch Hand
Posts: 230
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 230
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 230
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 230
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks and I agree that it is unlikely since I have several different printers and all (mis)behave the same.
 
Tony Docherty
Bartender
Pie
Posts: 2878
59
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 230
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 230
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Never mind. I got it. The call to pageDialog() was not necessary.
 
Jay Dilla
Ranch Hand
Posts: 201
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic