How to persist print dialog settings?

Discussion in 'Java' started by G.W. Lucas, Dec 8, 2009.

  1. G.W. Lucas

    G.W. Lucas Guest

    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.
    G.W. Lucas, Dec 8, 2009
    #1
    1. Advertising

  2. 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
    Knute Johnson, Dec 8, 2009
    #2
    1. Advertising

  3. G.W. Lucas

    Roedy Green Guest

    On Tue, 8 Dec 2009 07:49:39 -0800 (PST), "G.W. Lucas"
    <> wrote, quoted or indirectly quoted someone who
    said :

    >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?


    This is not what you wanted to hear, but you may be stuck doing a
    screen capture. See http://mindprod.com/jgloss/screencapture.html
    and follow links.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    The future has already happened, it just isn’t evenly distributed.
    ~ William Gibson (born: 1948-03-17 age: 61)
    Roedy Green, Dec 9, 2009
    #3
  4. G.W. Lucas

    G.W. Lucas Guest

    On Dec 9, 12:56 am, Roedy Green <>
    wrote:

    > This is not what you wanted to hear, but you may be stuck doing a
    > screen capture.  Seehttp://mindprod.com/jgloss/screencapture.html
    > and follow links.


    Thanks, Roedy. I've visited your site many times. While a screen
    capture would most certainly not solve my problem (for one thing, I'm
    very concerned about dimensional accuracy in my printouts), it is
    something I need to look into for another application. A user can do a
    screen capture by hitting the print screen button and pasting into
    Paint or other such application, but I'd like to streamline the
    process by sending the output directly to a PNG file from the
    application (life is too short to ask the user to mess around with a
    lot of spurious mouse interactions).

    Do you have a snippet of code for grabbing the screen as a Java
    BufferedImage or some such form?

    g.
    G.W. Lucas, Dec 9, 2009
    #4
  5. G.W. Lucas

    Roedy Green Guest

    On Wed, 9 Dec 2009 07:11:29 -0800 (PST), "G.W. Lucas"
    <> wrote, quoted or indirectly quoted someone who
    said :

    >Thanks, Roedy. I've visited your site many times. While a screen
    >capture would most certainly not solve my problem (for one thing, I'm
    >very concerned about dimensional accuracy in my printouts), it is
    >something I need to look into for another application. A user can do a
    >screen capture by hitting the print screen button and pasting into
    >Paint or other such application, but I'd like to streamline the
    >process by sending the output directly to a PNG file from the
    >application (life is too short to ask the user to mess around with a
    >lot of spurious mouse interactions).
    >
    >Do you have a snippet of code for grabbing the screen as a Java
    >BufferedImage or some such form?


    I think you can also capture text. I have not played with this, but I
    think you can under program control turn the pixels of any rectangle
    on the screen into a png.

    See http://mindprod.com/jgloss/pngencoder.html
    for some sample code to save an image as a png.

    --
    Roedy Green Canadian Mind Products
    http://mindprod.com
    The future has already happened, it just isn’t evenly distributed.
    ~ William Gibson (born: 1948-03-17 age: 61)
    Roedy Green, Dec 11, 2009
    #5
    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:
    897
  2. donet programmer
    Replies:
    3
    Views:
    1,516
    Gregory A. Beamer
    Nov 20, 2009
  3. Knute Johnson
    Replies:
    3
    Views:
    1,529
    Knute Johnson
    Dec 9, 2009
  4. Matt
    Replies:
    1
    Views:
    268
    Randy Webb
    Nov 20, 2004
  5. FAQ server
    Replies:
    0
    Views:
    92
    FAQ server
    Sep 5, 2006
Loading...

Share This Page