[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 351
  • Last Modified:

Printer-questions

How can I get/set the paper tray of printers? My intentions are to allow people to select a printer from inside a java-applet & let them set the printer and the papertray and store those in a server-sided database.
Then when they want to print something I want to programmaticaly set the bin/printer and print on that one.

So what I need (in order of importance):
- How to get/set paper format (-)
- How to get/set the printer name (+)
- How to get/set the paper tray (++)

Thanks
0
half_life_fool
Asked:
half_life_fool
  • 7
  • 4
1 Solution
 
Giant2Commented:
See here:
http://www.javaalmanac.com/cgi-bin/search/find.pl?words=Print
There are some example to print settings.
About the insert into DB you can use a normal JDBC (I believe you know how to use it).

Bye, Giant.
0
 
lcwidingCommented:
First, you will need to use the Properties class to set the properties you want. In order to determine the correct values, that will depend on the printer.

But, perhaps more importantly, this does not work on most Java releases.
0
 
half_life_foolAuthor Commented:
Is it possible to give some examples? Because I am totally puzzled here. I am rather good at C++, but this Java thing eludes me :(
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
lcwidingCommented:
You would start the prinjob with:

Properties prop = new Properties();
Toolkit tk = getToolkit();
PrintJob pj = tk.getPrintJob(frame, "job title", prop);

This will work in all JRE releases (Microsoft, Sun, ...);

For Sun JRE 1.3 and later, you can use:

JobAttributes ja = new JobAttributes();
ja.setDialog(JobAttributes.DialogType.NONE);
ja.setPrinter("printer name");
PageAttributes pa = new PageAttributes();
PrintJob = tk.setPrintJob(frame, "job title", ja, pa);

I did not find a way to set the tray using these, and how well they work still depends on the printer in the user's system, and whether or not it supports these functions. I have not used the second form mysefl, because the needs of my applications have required suport for 1.1, and have not had need for the level of support granted by the newer method.

For more informatio on these, see:
http://java.sun.com/j2se/1.3/docs/api/java/awt/JobAttributes.html
http://java.sun.com/j2se/1.3/docs/api/java/awt/PageAttributes.html
0
 
half_life_foolAuthor Commented:
       JobAttributes theJobAttribs = new JobAttributes();
        theJobAttribs.setDialog( JobAttributes.DialogType.NONE );
        theJobAttribs.setPrinter("PDFCreator");
       
        PageAttributes thePageAttribs = new PageAttributes();
        thePageAttribs.setMedia( PageAttributes.MediaType.LETTER );
//        thePageAttribs.setMedia( MediaTray.MAIN );
       
        PrintJob myJob = getToolkit().getPrintJob(this, "PrintJob", theJobAttribs, thePageAttribs);
        myJob.setAttribute();
        if (myJob != null) {
            Graphics g = myJob.getGraphics();
           
            if (g != null) {
                printText(myJob, g, "yeqsd");
                g.dispose();
            }
           
            myJob.end();
        }


This however gives an error on getToolkit() & on printText()

Also there SHOULD be a possibility to get/set the MediaTray.

http://java.sun.com/j2se/1.5.0/docs/api/javax/print/attribute/standard/MediaTray.html

0
 
lcwidingCommented:
What errors are generated by these calls?

getToolkit() is defined in java.awt.Component, so it shuold be callable from within any class that extends that.

I have not used the javax.print classes, but yes, it does look like you could use DocPrintJob to add the additional support you mention. The only caveat is that I am not sure with JRE that was implemented in, or if that is a concern for you.
0
 
half_life_foolAuthor Commented:
D:\Documents and Settings\Steven\JavaApplication2\src\javaapplication2\Main.java:40: cannot find symbol
symbol  : method getPrintJob(javaapplication2.Main,java.lang.String,java.awt.JobAttributes,java.awt.PageAttributes)
location: class java.awt.Toolkit
        PrintJob myJob = getToolkit().getPrintJob(this, "PrintJob", theJobAttribs, thePageAttribs);
D:\Documents and Settings\Steven\JavaApplication2\src\javaapplication2\Main.java:45: cannot find symbol
symbol  : method printText(java.awt.PrintJob,java.awt.Graphics,java.lang.String)
location: class javaapplication2.Main
                printText(myJob, g, "yeqsd");
2 errors
0
 
lcwidingCommented:
What version of Java are you running this under? The revised getPrintJob method was first made available with Java 1.3. If you are using an earlier release, you need to stick with my original recommendation. In that case, I would recommend that you start the print job, using the Print Dialgo to set the options that you want, and then, when getPrintJob() returns, dump the contents of the Properties object to the Java console, so you can preload those settings.

As for the printText method, I cannot speak to that, as I do not know that method. Is that one you wrote? If not, what class is it from?
0
 
half_life_foolAuthor Commented:
I'm running it under java 1.5.0.

I am coding in Netbeans 4.0 beta.

BTW, how do I dump that object to the Java console? Because when I set a watch in NB, it doesn't provide me with much usefull information...

Thx!
0
 
lcwidingCommented:
A simple way to output the properies object would be as follows:

properties.list(System.out);
0
 
lcwidingCommented:
I looked at the code you said was reporting errors. When I brought it up in Eclispe with the JDK 1.5 libraries, I got an error that setAttribute() was not a member of PrintJob, and could not find printText, which, as I said, looks like one of your methods.
0
 
lcwidingCommented:
I do not know if the author ever found a solution, though I tried to direct him as much as I could based on the information provided. My recommendation would be to mark my comment from 10/31/2004 05:26AM CST as accepted.
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 7
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now