How to persist print dialog settings?

G

G.W. Lucas

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.
 
K

Knute Johnson

G.W. Lucas said:
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.
 
R

Roedy Green

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.
 
G

G.W. Lucas

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.
 
R

Roedy Green

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top