Results 1 to 2 of 2
  1. #1
    bbq
    bbq is offline Senior Member
    Join Date
    Jun 2007
    Posts
    132
    Rep Power
    0

    Default 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;
    
    }
    }
    }

  2. #2
    Jack is offline Senior Member
    Join Date
    Jun 2007
    Posts
    130
    Rep Power
    0

Similar Threads

  1. Replies: 6
    Last Post: 04-08-2009, 05:05 AM
  2. AMD64 Java requires linux?
    By thaumielx72 in forum New To Java
    Replies: 3
    Last Post: 01-14-2008, 02:27 PM
  3. Linux process from java
    By Ed in forum New To Java
    Replies: 2
    Last Post: 07-04-2007, 06:03 AM
  4. Linux and java
    By Alan in forum Advanced Java
    Replies: 2
    Last Post: 05-31-2007, 03:30 PM
  5. print .doc in java
    By Alan in forum Advanced Java
    Replies: 1
    Last Post: 05-17-2007, 05:05 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •