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