Re: How to persist print dialog settings?

Discussion in 'Java' started by Knute Johnson, Dec 8, 2009.

  1. From: Knute Johnson <>

    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/38)
    --- Synchronet 3.15a-Win32 NewsLink 1.92
    * Time Warp of the Future BBS - Cougar, Washington - telnet://time.synchro.net
     
    Knute Johnson, Dec 8, 2009
    #1
    1. Advertising

  2. Knute Johnson wrote:
    > From: Knute Johnson <>
    >
    > 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/38)
    > --- 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
     
    Knute Johnson, Dec 9, 2009
    #2
    1. Advertising

  3. Knute Johnson

    G.W. Lucas Guest

    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
     
    G.W. Lucas, Dec 9, 2009
    #3
  4. 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
     
    Knute Johnson, Dec 9, 2009
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. keto
    Replies:
    0
    Views:
    965
  2. donet programmer
    Replies:
    3
    Views:
    1,554
    Gregory A. Beamer
    Nov 20, 2009
  3. G.W. Lucas
    Replies:
    4
    Views:
    934
    Roedy Green
    Dec 11, 2009
  4. Matt
    Replies:
    1
    Views:
    280
    Randy Webb
    Nov 20, 2004
  5. FAQ server
    Replies:
    0
    Views:
    105
    FAQ server
    Sep 5, 2006
Loading...

Share This Page