• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Urgent-printing the data onto the printer problem?

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
try this:
Graphics2D g2 = (Graphics)g
g2.setPaint(Color.black);
g2.translate(pf.getImageableX(), pf.getImageableY());
 
reply
    Bookmark Topic Watch Topic
  • New Topic