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 5 of 5

Thread: Java printer selection

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

    Default Java printer selection

    Hi All

    As part of my program, I need to submit certain documents to one tray(with preprinted paper) and other documents to default tray.

    I have used the following options with out luck.

    1. Programmatically setting the printer by passing the following code in my attribute set

    PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();
    attributeSet.add(MediaTray.MIDDLE);

    2. programmatically setting the printer by the following option

    Media med[] = (Media[])service.getSupportedAttributeValues(Media.class, null, null);
    for (int k=0; k<med.length; k++) {
    if(med[k].getClass().equals(sun.print.Win32MediaTray.class) &&
    med[k].toString().trim().contains("Tray 2")) {
    SunAlternateMedia am = new SunAlternateMedia(med[k]);
    attributeSet.add(am);
    }

    3. created a logical printer by disabling all the trays except "tray 2" in printer properties. In this scenario, if I print a pdf document using acrobat reader and selected my newly created logical printer, printer was printing on certified paper. The same is not possible through my java program

    4. Created a custom size for tray 2 by adding 0.01 inches more to the letter size and defined the same in my java program as follows.

    float printableX = (float)8.51;
    float printableY = (float)11.01;
    PrintRequestAttributeSet attributeSet = new HashPrintRequestAttributeSet();;
    MediaSizeName mediaSizeName = MediaSize.findMedia(printableX,printableY,MediaPrintableArea.INCH);
    attributeSet.add(mediaSizeName);
    PrintService[] services = PrintServiceLookup.lookupPrintServices(flavor, null);
    PrintService service =(PrintService)services;
    if(service.getName().contains("NEW_MAIL2")){
    System.out.println(" printername ::"+service.getName());
    DocPrintJob job = service.createPrintJob();
    Doc doc = new SimpleDoc(is, flavor, null);
    job.print(doc, attributeSet);
    }
    Any suggestions please!!!

    My printer is HP LaserJet 9050 PCL 5e

    Thanks in advance,
    Gupta


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: Java printer selection

    Hello pnvsgupta. Welcome to the Java Programming Forums.

    It's hard for us to test this out. When you say you have had no luck, what happens? Does anything print?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

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

    Default Re: Java printer selection

    For all the above 4 scenarios, printer is always printing from default tray.
    I am not sure how to pick an appropriate tray through java program.

  4. #4
    Forum VIP
    Join Date
    Jun 2011
    Posts
    317
    My Mood
    Bored
    Thanks
    47
    Thanked 89 Times in 74 Posts
    Blog Entries
    4

    Default Re: Java printer selection

    The HP LaserJet 8150 drivers had a strange quirk. The manual tray would only support printing image files. I was unable to resolve this issue at the time so I gave up on it. I considered writing a hack that converted the PDF's to PNG's but again, I gave up on that idea as it is deceptively complex. It is pretty safe to assume that the 9050 PCL 5e suffers the same problem.

    If you do find a solution to this I would LOVE to hear about it.

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

    Default Re: Java printer selection

    Quote Originally Posted by ChristopherLowe View Post
    The HP LaserJet 8150 drivers had a strange quirk. The manual tray would only support printing image files. I was unable to resolve this issue at the time so I gave up on it. I considered writing a hack that converted the PDF's to PNG's but again, I gave up on that idea as it is deceptively complex. It is pretty safe to assume that the 9050 PCL 5e suffers the same problem.

    If you do find a solution to this I would LOVE to hear about it.
    I could not able to resolve this issue using java print api, because of my project deadlines, I had to use acrord32.exe to print the pdfs by using Runtime.proc

    Thanks

Similar Threads

  1. Basic Java Sorting Algorithm (Selection/Insertion) help
    By Arte7 in forum Algorithms & Recursion
    Replies: 5
    Last Post: August 22nd, 2011, 01:38 PM
  2. send image (logo) and text & barcode to the Zebra Printer
    By ehsanlinux in forum What's Wrong With My Code?
    Replies: 3
    Last Post: June 11th, 2011, 05:41 AM
  3. Replies: 0
    Last Post: April 8th, 2011, 09:17 PM
  4. How to print out data from web page to printer????
    By verma86 in forum JavaServer Pages: JSP & JSTL
    Replies: 0
    Last Post: April 2nd, 2010, 10:26 PM
  5. Selection Sorting
    By chronoz13 in forum Algorithms & Recursion
    Replies: 5
    Last Post: December 10th, 2009, 11:08 AM