Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Printing Files using DocPrintJob

  1. #1
    Junior Member
    Join Date
    Jun 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Printing Files using DocPrintJob

    Hi all,


    I've been trying to print files to an EPSON Dot Matrix printer. I'm sending raw data to the printer. When I print one file, the routine works fine. But when I tried printing multiple files, that is by calling the .print() method, nothing gets printed at all.. Can anybody explain why this happens? And how can I try to print multiple files? I've tried getting it on an array but still it doesn't work. By the way, here is my code:

    public void printTheFile(String file){
    PrintService ps = PrintServiceLookup.lookupDefaultPrintService();
    try {
    if (ps!=null){
    PrintRequestAttributeSet aset= new HashPrintRequestAttributeSet();
    DocFlavor flavor = DocFlavor.INPUT_STREAM.AUTOSENSE;
    aset.add(new MediaPrintableArea (9,21,200,139,Size2DSyntax.MM));
    Doc pj = ps.createPrintJob();
    try {
    InputStream b = new BufferedInputStream(new FileInputStream(file));
    Doc doc = new SimpleDoc(b, flavor, null);
    pj.print(doc, aset);
    }catch (PrintException e){
    e.printStackTrace();
    }catch(Exception e) {
    e.printStackTrace();
    }//catch
    }
    }catch (Exception e){
    e.printStackTrace();
    }//catch
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,166
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Printing Files using DocPrintJob

    Hard to tell what your code does with only this small piece. Please use code tags to keep code formatting.
    What does the code do if ps==null?

  3. #3
    Junior Member
    Join Date
    Jun 2010
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Printing Files using DocPrintJob

    Hi Norm, I guess ps will only be null if there is no default printer set on the machine. I still haven't resolved this issue yet but somehow, I found another solution that will make my code work.

Similar Threads

  1. [SOLVED] Printing Array without printing empty elements
    By CarlMartin10 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 12th, 2010, 02:41 AM
  2. JOptionPane Question/ Printing
    By 03EVOAWD in forum AWT / Java Swing
    Replies: 2
    Last Post: August 31st, 2009, 09:17 AM
  3. Printing a JTable
    By hundu in forum AWT / Java Swing
    Replies: 0
    Last Post: June 29th, 2009, 08:15 AM
  4. How to printing a Jtable
    By hundu in forum AWT / Java Swing
    Replies: 0
    Last Post: June 29th, 2009, 06:57 AM
  5. Printing JTable that retrieve data from the Database
    By hundu in forum AWT / Java Swing
    Replies: 3
    Last Post: June 28th, 2009, 01:50 PM

Tags for this Thread