Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Urgent-printing the data onto the printer problem?

 
shashi kale
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
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
{
try
{
StringBuffer objStringBuffer = new StringBuffer();
RandomAccessFile objRandomAccessFile = new RandomAccessFile(fname,"rw");
long flength = objRandomAccessFile.read();
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 " );
objRandomAccessFile.close();
g.setFont(fnt);
g.setColor(Color.black);
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())
{
try
{
pj.print();
}
catch (Exception e)
{
e.printStackTrace();
}
Thanks in advance

 
Le Wang
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
try this:
Graphics2D g2 = (Graphics)g
g2.setPaint(Color.black);
g2.translate(pf.getImageableX(), pf.getImageableY());
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic