Printing a report in the form of a text file
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Arunoday_Chatterjee
Posted On:   Sunday, May 13, 2001 10:18 PM

I would like to print a text file or any other file as a report but I couldn't find any printing option - the only thing that I could find was PrintJob class in Java.awt.Toolkit - but it accepts a frame in its constructor and seems to print only graphics - but I would like to print a text file.

Also, how do I read the available installed printers in the machine of the user and display a printer chooser dialog box like that of file chooser or color chooser - is there a way to do it?

Pls. let me know ASAP as this is very urgent for me.

Re: Printing a report in the form of a text file

Posted By:   Sachin_Patil  
Posted On:   Wednesday, May 16, 2001 11:37 PM

Code below should solve your problem:

import java.awt.print.*;
public class PrintProfile {
public PrintProfile() {
}
public void pagePrint(){
try {
PrinterJob printerJob = PrinterJob.getPrinterJob();
PageFormat formating = new PageFormat();
formating = printerJob.pageDialog(formating);
printerJob.setJobName("c:\sachin.txt");

boolean doPrint = printerJob.printDialog();
if (doPrint)
printerJob.print();
}
catch (PrinterException exception){
System.err.println("Printing error: " +exception);
}
}

}
About | Sitemap | Contact