wood burning stoves 2.0*
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
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
Author

Urgent-printing the data onto the printer problem?

shashi kale
Greenhorn

Joined: Sep 26, 2001
Posts: 7
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

Joined: Oct 09, 2001
Posts: 10
Hi,
try this:
Graphics2D g2 = (Graphics)g
g2.setPaint(Color.black);
g2.translate(pf.getImageableX(), pf.getImageableY());
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Urgent-printing the data onto the printer problem?
 
Similar Threads
Urgent....
printing in java 1.4
how to write a printing code in java
Printing on JTextArea
printing - can't have a '\n' new line. everything is concatenated :-(