This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Swing / AWT / SWT and the fly likes Urgent-printing the data onto the printer problem? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Urgent-printing the data onto the printer problem?" Watch "Urgent-printing the data onto the printer problem?" New topic

Urgent-printing the data onto the printer problem?

shashi kale

Joined: Sep 26, 2001
Posts: 7
i would likt to print the data from text file say abc.txt onto the printer,it actully fires the trigger to printer but wont print anything.
need urgent help....
the code which paints :
class PaintCover implements Printable {
Font fnt = new Font("Courier New", Font.PLAIN,10);
String fname;
public PaintCover(String fname)
this.fname = fname;
public int print(Graphics g, PageFormat pf, int pageIndex) throws PrinterException
StringBuffer objStringBuffer = new StringBuffer();
RandomAccessFile objRandomAccessFile = new RandomAccessFile(fname,"rw");
long flength =;
System.out.println("lenth of file" + flength);
for(long index = 0 ; index < flength;index ++)
objStringBuffer= objStringBuffer.append(objRandomAccessFile.readLine());
System.out.print(objStringBuffer + "File contents " );
g.drawString(objStringBuffer.toString(), 50, 50);
catch(Exception e)
return Printable.PAGE_EXISTS;

2:Calling funtion is
PrinterJob pj = PrinterJob.getPrinterJob();
pj.setPrintable(new PaintCover(this.fname));
if (pj.printDialog())
catch (Exception e)
Thanks in advance

Le Wang

Joined: Oct 09, 2001
Posts: 10
try this:
Graphics2D g2 = (Graphics)g
g2.translate(pf.getImageableX(), pf.getImageableY());
I agree. Here's the link:
subject: Urgent-printing the data onto the printer problem?
It's not a secret anymore!