Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-22-2007, 02:46 PM
bbq bbq is offline
Senior Member
 
Join Date: Jun 2007
Posts: 134
bbq is on a distinguished road
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

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; } } }
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 07-05-2007, 05:24 AM
Senior Member
 
Join Date: Jun 2007
Posts: 130
Jack is on a distinguished road
Do you have some exception? or just doesn't print?
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Linux conflict - TrayIcon image not display in Linux Eranga Advanced Java 0 03-25-2008 06:37 AM
AMD64 Java requires linux? thaumielx72 New To Java 3 01-14-2008 02:27 PM
Linux process from java Ed New To Java 2 07-04-2007 06:03 AM
Linux and java Alan Advanced Java 2 05-31-2007 03:30 PM
print .doc in java Alan Advanced Java 1 05-17-2007 05:05 AM


All times are GMT +3. The time now is 02:07 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org