Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Re: How to persist print dialog settings?

Reply
Thread Tools

Re: How to persist print dialog settings?

 
 
Knute Johnson
Guest
Posts: n/a
 
      12-08-2009
From: Knute Johnson <(E-Mail Removed)>

G.W. Lucas wrote:
> I am trying to add a print capability to an application I am writing
> and am having trouble getting the application to retain the settings
> for ˘landscape÷ versus ˘portrait÷ each time the print dialog is
> raised. That is, if the user sets landscape instead of portrait
> orientation the first time he prints, IĂd like it to show landscape in
> all subsequent times he raises the print dialog. I am less concerned
> about other settings. Unfortunately, IĂve not been successful with any
> of them. Could someone point me in the right direction?
>
> I am running under Windows XP Service Pack 3. Java 1.6.0_16.
>
> To raise the printDialog, I do the following:
>
> PrinterJob printerJob = PrinterJob.getPrinterJob();
> printerJob.printDialog();
>
> This brings up a dialog which resembles the Microsoft Office
> applications and provides a Properties-button dialog that is
> consistent with the properties for my printer. But it doesnĂt retain
> the page-orientation settings from invocation to invocation. I tried
> the following:
>
> HashPrintRequestAttributeSet hpas = new HashPrintRequestAttributeSet
> ();
> printJob.printDialog(hpas);
>
> Which does allow me to retain the settings, but the print dialog looks
> completely different and, worse, does not bring up a Properties dialog
> at all. Nor does it include all the metadata for the printer that is
> available using the no-arguments printDialog() call. I could use this
> approach, but would really like to be able to show my users a dialog
> that is compatible with their other applications and gives them full
> access to the capabilities of their printer.
>
> Does anyone a recommendations for using the print dialog that might
> address this issue? Would this be addressed by using better way to
> set up the PrintRequestAttributeSet? Is there a different approach
> other than using a PrintRequestAttributeSet?
>
> Thanks.
>
> Gary
>
> P.S. On a positive note, the printouts look really sharp and the Java
> Graphics2D stuff is extremely accurate and a joy to use.


You need a PageFormat to print. Keep the same PageFormat for the life of the
program. When you exit, save the orientation state and restore that when you
restart the program.

--

Knute Johnson
email s/nospam/knute2009/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access

--- BBBS/LiI v4.01 Flag
* Origin: Prism bbs (1:261/3
--- Synchronet 3.15a-Win32 NewsLink 1.92
* Time Warp of the Future BBS - Cougar, Washington - telnet://time.synchro.net
 
Reply With Quote
 
 
 
 
Knute Johnson
Guest
Posts: n/a
 
      12-09-2009
Knute Johnson wrote:
> From: Knute Johnson <(E-Mail Removed)>
>
> G.W. Lucas wrote:
>> I am trying to add a print capability to an application I am writing
>> and am having trouble getting the application to retain the settings
>> for ´┐Żlandscape´┐Ż versus ´┐Żportrait´┐Ż each time the print dialog is
>> raised. That is, if the user sets landscape instead of portrait
>> orientation the first time he prints, I´┐Żd like it to show landscape in
>> all subsequent times he raises the print dialog. I am less concerned
>> about other settings. Unfortunately, I´┐Żve not been successful with any
>> of them. Could someone point me in the right direction?
>>
>> I am running under Windows XP Service Pack 3. Java 1.6.0_16.
>>
>> To raise the printDialog, I do the following:
>>
>> PrinterJob printerJob = PrinterJob.getPrinterJob();
>> printerJob.printDialog();
>>
>> This brings up a dialog which resembles the Microsoft Office
>> applications and provides a Properties-button dialog that is
>> consistent with the properties for my printer. But it doesn´┐Żt retain
>> the page-orientation settings from invocation to invocation. I tried
>> the following:
>>
>> HashPrintRequestAttributeSet hpas = new HashPrintRequestAttributeSet
>> ();
>> printJob.printDialog(hpas);
>>
>> Which does allow me to retain the settings, but the print dialog looks
>> completely different and, worse, does not bring up a Properties dialog
>> at all. Nor does it include all the metadata for the printer that is
>> available using the no-arguments printDialog() call. I could use this
>> approach, but would really like to be able to show my users a dialog
>> that is compatible with their other applications and gives them full
>> access to the capabilities of their printer.
>>
>> Does anyone a recommendations for using the print dialog that might
>> address this issue? Would this be addressed by using better way to
>> set up the PrintRequestAttributeSet? Is there a different approach
>> other than using a PrintRequestAttributeSet?
>>
>> Thanks.
>>
>> Gary
>>
>> P.S. On a positive note, the printouts look really sharp and the Java
>> Graphics2D stuff is extremely accurate and a joy to use.

>
> You need a PageFormat to print. Keep the same PageFormat for the life of the
> program. When you exit, save the orientation state and restore that when you
> restart the program.
>
> --
>
> Knute Johnson
> email s/nospam/knute2009/
>
> --
> Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
> ------->>>>>>http://www.NewsDemon.com<<<<<<------
> Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
>
> --- BBBS/LiI v4.01 Flag
> * Origin: Prism bbs (1:261/3
> --- Synchronet 3.15a-Win32 NewsLink 1.92
> * Time Warp of the Future BBS - Cougar, Washington - telnet://time.synchro.net


What's with this echo?

--

Knute Johnson
email s/nospam/knute2009/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
 
Reply With Quote
 
 
 
 
G.W. Lucas
Guest
Posts: n/a
 
      12-09-2009
On Dec 8, 4:05*pm, "Knute Johnson" <knute.johnson@1:261/38.remove-n3i-
this> wrote:
>
> You need a PageFormat to print. *Keep the same PageFormat for the life of the
> program. *When you exit, save the orientation state and restore that when you
> restart the program.
>


Thanks. I've looked at PageFormat and I'm afraid it's not going to
solve my problem. Here's the thing... the nature of my graphics is
that most of the time they ought to be printed with a landscape
orientation. The default paper orientation for almost every
application in the known universe is, of course, portrait. With that
in mind, the ideal solution would be for the application would let the
user pick an orientation the first time he prints and then present him
with that same value every time after that. As a compromise solution,
it would probably be okay if the Java print dialog could persist the
settings from invocation to invocation within the same run of the
application, but Java doesn't do that. So right now, I am stuck with
making the user pick the paper orientation every time they print.
They're going to hate that.

There are two printDialog methods. One takes no arguments and one
takes a PrintRequestAttributeSet. In theory the attribute set can be
used as a way of persisting settings. The problem is that when I pass
one in, Java gives me a different dialog (one which I consider pretty
hokey looking and, worse, doesn't allow the user to access all the
printer Properties).

Failing a better solution, I'm VERY RELUCTANTLY going to call this a
Java bug and do a work around. When you set up a Java PrinterJob, you
register an instance of the Printable interface which implements a
method called print() which is where your code is supposed to do all
its work. The print() method does get a PageFormat object. I can have
the program look at the page dimensions and orientation and
automatically pick an orientation for the user. This approach would
commit the minor affront of ignoring whatever the user selected for
his orientation, but I hope that most of the time he won't care.

Gary
 
Reply With Quote
 
Knute Johnson
Guest
Posts: n/a
 
      12-09-2009
G.W. Lucas wrote:
> On Dec 8, 4:05 pm, "Knute Johnson" <knute.johnson@1:261/38.remove-n3i-
> this> wrote:
>> You need a PageFormat to print. Keep the same PageFormat for the life of the
>> program. When you exit, save the orientation state and restore that when you
>> restart the program.
>>

>
> Thanks. I've looked at PageFormat and I'm afraid it's not going to
> solve my problem. Here's the thing... the nature of my graphics is
> that most of the time they ought to be printed with a landscape
> orientation. The default paper orientation for almost every
> application in the known universe is, of course, portrait. With that
> in mind, the ideal solution would be for the application would let the
> user pick an orientation the first time he prints and then present him
> with that same value every time after that. As a compromise solution,
> it would probably be okay if the Java print dialog could persist the
> settings from invocation to invocation within the same run of the
> application, but Java doesn't do that. So right now, I am stuck with
> making the user pick the paper orientation every time they print.
> They're going to hate that.


You are not paying attention. You can set the orientation in the
PageFormat object anytime you want. This will present your selected
orientation in the print dialog. Do it at the beginning, have the user
select it the first time, it doesn't matter. Keep the same PageFormat
object and the orientation (and all of the other fields too) will persist.

> There are two printDialog methods. One takes no arguments and one
> takes a PrintRequestAttributeSet. In theory the attribute set can be
> used as a way of persisting settings. The problem is that when I pass
> one in, Java gives me a different dialog (one which I consider pretty
> hokey looking and, worse, doesn't allow the user to access all the
> printer Properties).


So don't use that, do what I suggested above.

> Failing a better solution, I'm VERY RELUCTANTLY going to call this a
> Java bug and do a work around. When you set up a Java PrinterJob, you
> register an instance of the Printable interface which implements a
> method called print() which is where your code is supposed to do all
> its work. The print() method does get a PageFormat object. I can have
> the program look at the page dimensions and orientation and
> automatically pick an orientation for the user. This approach would
> commit the minor affront of ignoring whatever the user selected for
> his orientation, but I hope that most of the time he won't care.


See previous comment.

I've got running code with this in it. It works fine.

--

Knute Johnson
email s/nospam/knute2009/

--
Posted via NewsDemon.com - Premium Uncensored Newsgroup Service
------->>>>>>http://www.NewsDemon.com<<<<<<------
Unlimited Access, Anonymous Accounts, Uncensored Broadband Access
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
How to persist print dialog settings? G.W. Lucas Java 4 12-11-2009 03:48 AM
Problem - I want to print Current Output of Pdf file and should print once.I get print dialog box but it is not working keto Java 0 05-30-2007 11:27 AM
display print preview dialog, not print dialog Matt Javascript 1 11-20-2004 01:18 AM
Cannot press OK in Windows Print Dialog / How can i print in Windows ? mzo Python 0 01-13-2004 04:55 PM



Advertisments