Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Printer-questions

Posted on 2004-10-27
15
Medium Priority
?
347 Views
Last Modified: 2008-01-09
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
Comment
Question by:half_life_fool
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
15 Comments
 
LVL 12

Expert Comment

by:Giant2
ID: 12430865
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
 
LVL 4

Expert Comment

by:lcwiding
ID: 12445814
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
 

Author Comment

by:half_life_fool
ID: 12456217
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 4

Expert Comment

by:lcwiding
ID: 12456313
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
 

Author Comment

by:half_life_fool
ID: 12456341
       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
 
LVL 4

Expert Comment

by:lcwiding
ID: 12457007
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
 

Author Comment

by:half_life_fool
ID: 12457434
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
 
LVL 4

Expert Comment

by:lcwiding
ID: 12458406
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
 

Author Comment

by:half_life_fool
ID: 12460902
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
 
LVL 4

Accepted Solution

by:
lcwiding earned 1000 total points
ID: 12462488
A simple way to output the properies object would be as follows:

properties.list(System.out);
0
 
LVL 4

Expert Comment

by:lcwiding
ID: 12467216
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
 
LVL 4

Expert Comment

by:lcwiding
ID: 12784841
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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This video teaches viewers about errors in exception handling.
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question