Results 1 to 2 of 2
Thread: print in java linux
- 06-22-2007, 01:46 PM #1
Senior Member
- Join Date
- Jun 2007
- Posts
- 132
- Rep Power
- 0
print in java linux
I'm developing an application that must print a voucher of buy.
I've found the code on the Internet, I tested it and It works! but I want that the code works in Suse 10.1 too
but it doesn't.
Do you know what is the problem?
check my code please
Java Code:public class JavaWorldPrintExample3 { public static void main(String[] args) { JavaWorldPrintExample3 example3 = new JavaWorldPrintExample3(); System.exit(0); } //--- Private instances declarations private final static int POINTS_PER_INCH = 10; public JavaWorldPrintExample3() { //--- Create a new PrinterJob object PrinterJob printJob = PrinterJob.getPrinterJob(); //--- Create a new book to add pages to Book book = new Book(); //--- Add the cover page using the default page format for this print // job book.append(new IntroPage(250), printJob.defaultPage()); //--- Add the document page using a landscape page format PageFormat documentPageFormat = new PageFormat(); documentPageFormat.setOrientation(PageFormat.PORTRAIT); //--- Tell the printJob to use the book as the pageable object //printJob.setPageable(book); printJob.setPrintable(new IntroPage(250), documentPageFormat); //--- 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(); } //} } private class IntroPage implements Printable { int y; public IntroPage(int x){ y=x; } public int print(Graphics g, PageFormat pageFormat, int page) { if(page == 0){ // --- 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 default drawing color to black g2d.setPaint(Color.black); //--- Print the title String titleText = "....."; Font titleFont = new Font("Dialog", Font.PLAIN, 10); g2d.setFont(titleFont); //--- Compute the horizontal center of the page g2d.drawString("John Brown", 37, 20); g2d.drawString("NIT.40.440.805-6", 50, 30); g2d.drawString("Date 2007/06/15", 50, 60); g2d.drawString("Number from 00001 to 10000", 30, 70); g2d.drawString("Quantity.", 10, 100); g2d.drawString("Vlr/Unit", 40, 100); g2d.drawString("-------", 10, 110); g2d.drawString("--------", 40, 110); return (PAGE_EXISTS); } else return NO_SUCH_PAGE; } } }
- 07-05-2007, 04:24 AM #2
Senior Member
- Join Date
- Jun 2007
- Posts
- 130
- Rep Power
- 0
Similar Threads
-
[SOLVED] Windows Linux conflict - TrayIcon image not display in Linux
By Eranga in forum Advanced JavaReplies: 6Last Post: 04-08-2009, 04:05 AM -
AMD64 Java requires linux?
By thaumielx72 in forum New To JavaReplies: 3Last Post: 01-14-2008, 01:27 PM -
Linux process from java
By Ed in forum New To JavaReplies: 2Last Post: 07-04-2007, 05:03 AM -
Linux and java
By Alan in forum Advanced JavaReplies: 2Last Post: 05-31-2007, 02:30 PM -
print .doc in java
By Alan in forum Advanced JavaReplies: 1Last Post: 05-17-2007, 04:05 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks