Hi, I am really newbie in Java
I need to build an applet that prints a text, but, it can not roll the page
I mean, when I print like
"TEST ONE
TEST TWOO
TEST THREEE"
the printer can not roll the paper below the three lines
because I am using those fiscal printers...
down below is the, modified, code I found in internet...
i am trying to do that in about 4 hours without any good result.
the page is still be swalled by the printer, making the fiscal paper losing its right position
please, any help would be appreciated
I need to build an applet that prints a text, but, it can not roll the page
I mean, when I print like
"TEST ONE
TEST TWOO
TEST THREEE"
the printer can not roll the paper below the three lines
because I am using those fiscal printers...
down below is the, modified, code I found in internet...
i am trying to do that in about 4 hours without any good result.
the page is still be swalled by the printer, making the fiscal paper losing its right position
please, any help would be appreciated
Code:
import java.awt.*;
import java.awt.font.*;
import java.awt.geom.*;
import java.awt.print.*;
import java.awt.image.*;
import java.text.*;
import java.net.*;
public class Example6 {
//--- Private instances declarations
private final static int POINTS_PER_INCH = 72;
/**
* Constructor: Example6 <p>
*
*/
public Example6 () {
//--- Create a new PrinterJob object
PrinterJob printJob = PrinterJob.getPrinterJob ();
//--- Create a new book to add pages to
Book book = new Book ();
//--- Add the document page using a landscape page format
PageFormat documentPageFormat = new PageFormat ();
documentPageFormat.setOrientation (PageFormat.LANDSCAPE);
//Paper paper = documentPageFormat.getPaper();
Paper paper = new Paper();
// Limit paper width and height
paper.setSize(120, 120);
paper.setImageableArea(10, 10, 80, 80);
// set the paper to this, edited one
documentPageFormat.setPaper(paper);
book.append (new Document (), documentPageFormat);
//--- Tell the printJob to use the book as the pageable object
printJob.setPageable (book);
//--- Show the print dialog box. If the user click the
//--- print button we then proceed to print else we cancel
//--- the process.
if (printJob.printDialog()) {
try {
printJob.print();
} catch (Exception PrintException) {
PrintException.printStackTrace();
}
}
}
/**
* Class: Document <p>
*
* This class is the painter for the document content. In this example,
*/
private class Document extends Component implements Printable {
/**
* Method: print <p>
*
* @param g a value of type Graphics
* @param pageFormat a value of type PageFormat
* @param page a value of type int
* @return a value of type int
*/
public int print (Graphics g, PageFormat pageFormat, int page) {
//--- Create the Graphics2D object
Graphics2D g2d = (Graphics2D) g;
//--- Translate the origin to 0,0 for the top left corner
g2d.translate (pageFormat.getImageableX (), pageFormat.getImageableY ());
//--- Set the drawing color to black
g2d.setPaint (Color.black);
//--- Draw a border arround the page using a 12 point border
//g2d.setStroke (new BasicStroke (4));
Rectangle2D.Double border = new Rectangle2D.Double (0,
0,
pageFormat.getImageableWidth (),
pageFormat.getImageableHeight ());
g2d.draw (border);
Font titleFont = new Font ("Courier New", Font.BOLD, 10);
g2d.setFont (titleFont);
g2d.drawString("w=" + pageFormat.getWidth(), 20, 20);
//--- Validate the page
return (PAGE_EXISTS);
}
}
} // Example6
Comment