Go Premium for a chance to win a PS4. Enter to Win

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

how to print?

Hi all,

In my program  I wanted to print the customer details stored in buffer . what class library I need to import & how am I to go about it ?
can anyone help me out in solving this problem.

Thanks
shanth
0
shanth_77
Asked:
shanth_77
  • 4
  • 3
1 Solution
 
Venci75Commented:
try this code:
java.awt.Frame frame = new java.awt.Frame("Title");
java.util.Properties properties = new java.util.Properties();
//create a print jobjava.awt.PrintJob pj = java.awt.Toolkit.getDefaultToolkit().getPrintJob(frame, "jobtitle", properties);
//use the print job graphics object to draw the printings
pj.getGraphics().drawString("This is a test!", 10, 10);
pj.end();

all you need is the java.awt package ...
0
 
shanth_77Author Commented:
hi venci,
I tried with ur code as below but it generates an error with class not found for jobjava.awt.PrintJob
Please help me out proceed further.
It would be an good attempt if U can help me to issue the print command from dos-prompt.

import java.awt.*;
import java.util.*;
public class Prin{
public Prin()
{
java.awt.Frame frame = new java.awt.Frame("Title");
java.util.Properties properties = new java.util.Properties();
jobjava.awt.PrintJob pj = java.awt.Toolkit.getDefaultToolkit().getPrintJob(frame, "jobtitle", properties);
//use the print job graphics object to draw the printings

pj.getGraphics().drawString("This is a test!", 10, 10);
pj.end();
}

public static void main(String args[])
{
new Prin();
}

Thanx in advance
shanth_77
0
 
Venci75Commented:
Sorry - the correct line is:
java.awt.PrintJob pj = java.awt.Toolkit.getDefaultToolkit().getPrintJob(frame, "jobtitle", properties);

the "job" prefix should be part of the comment
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.

 
shanth_77Author Commented:
Hi Venci,
  I tried UR coding, its with no errors and complied fine with the print dialog box shown.But the content is not written to the frame.
The drawString does not work.Is it possible to direct the dos based application to direct to printing?
please help me out!!!!!!!!!!

thanx in advance.
shanth_77
0
 
Venci75Commented:
Hi shanth_77,

in the line:
pj.getGraphics().drawString("This is a test!", 10, 10);
the coordinates (10, 10) are not in the printable area. Sorry for this, but I haven't tried it.
I tried now with (200, 200) coordinates:
pj.getGraphics().drawString("This is a test!", 200, 200);
and the text was printed.

Regarding the DOS printing - yes it is possible, but I don't recomend it to you. The way is to redirect the output of your application to the printer:
my_app.bat > LPT1
or
type my_file.txt > LPT1
0
 
shanth_77Author Commented:
Venci,
 Thanx for ur due help over the above.
But iam slightly confused with dos mode print of specifying the file to printer because i store my contents in bufferreader and not in a file.
can i still print out?

shanth_77
0
 
shanth_77Author Commented:
venci,
  I tried with ur advice as above, but when i show the frame there is no content as This is Test written.
Its not displayed.

pj.getGraphics().drawString("This is Test",100,100);
frame.show();
pj.end();

shanth_77
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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