wood burning stoves*
The moose likes Java in General and the fly likes Get file details and print Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Get file details and print" Watch "Get file details and print" New topic
Author

Get file details and print

michael yue
Ranch Hand

Joined: Nov 20, 2003
Posts: 204
Dear all,

I am trying to do a program that get the data from a file and send it straight to printing. My code is as below

import java.io.*;
import java.awt.*;
import java.awt.print.*;
import java.awt.geom.*;
//import java.sql.*;
import java.text.*;
import java.util.*;

class PrintObject implements Printable
{
public int print (Graphics g, PageFormat f, int pageIndex)
{

String str="NONE",str1="NONE1";
try{
BufferedReader in = new BufferedReader(new FileReader("text.txt"));

while ((str = in.readLine()) != null) {
str1=str1+str+"\n";


}

in.close();
} catch (IOException e) {
System.out.println(e);
}

System.out.println(str1);


switch (pageIndex)
{
case 0 : g.drawString(str1, 100,100);
return PAGE_EXISTS;

default: return NO_SUCH_PAGE; // No other pages
}
}
}

public class printest
{
public static void main (String[] args)
{
// Create an object that will hold all print parameters, such as
// page size, printer resolution. In addition, it manages the print
// process (job).
PrinterJob job = PrinterJob.getPrinterJob();

// It is first called to tell it what object will print each page.
job.setPrintable(new PrintObject());

// Then it is called to display the standard print options dialog.
if (job.printDialog())
{
// If the user has pressed OK (printDialog returns true), then go
// ahead with the printing. This is started by the simple call to
// the job print() method. When it runs, it calls the page print
// object for page index 0. Then page index 1, 2, and so on
// until NO_SUCH_PAGE is returned.
try { job.print(); }
catch (PrinterException e) { System.out.println(e); }
}
}
}

Problem is when run the program the print dialog box display there is 9999 pages to print. So i change the dialog box to print 1 page and the printing only came out 1 line. It also didnt leave a line meaning /n didnt perform. Can anyone correct me?
Thanks
Stefan Wagner
Ranch Hand

Joined: Jun 02, 2003
Posts: 1923

You have to set the y-coordinate yourself.

Just to give a starting point:


http://home.arcor.de/hirnstrom/bewerbung
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Get file details and print
 
Similar Threads
RandomAccessFile + Java printing
Retries is Java printing?
URGENT: Textured filled geometric shapes are not printed when the shapes are large
Printing an object
Problem in printing a pdf file using pdfrenderer