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: javax.print setting attributes

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default javax.print setting attributes

    There's no section for javax.print so -

    I have a program for printing a pdf file that was generated using the iText 2 package.
    The file is created as an A4 document.
    The program is able to load the file and send the print job - it reaches the printer, but on the printer the control panel prompts the user to load A4, Plain Paper. The print job will come out if the user presses "OK" on the printer to override and print to whatever paper is loaded.
    I need it to print directly without user intervention, as the same file prints directly from Adobe Reader without this problem.
    I also need it to print 2 copies and it only prints one.

    Here is the code for creating the print job:

    PrintRequestAttributeSet preqats = new HashPrintRequestAttributeSet();
    preqats.add(new Copies(2));
    preqats.add(MediaTray.MAIN);
    preqats.add(MediaSizeName.ISO_A4);
    job.print(doc, preqats);

    I am running this on a Windows 7 32-bit machine.
    Printer model is HP LJ P3015.
    The printer is hosted on a Windows Server 2003 machine.
    I have set the printer defaults to:
    Paper size = A4
    Paper source = Auto
    Paper Type = Unspecified

    In the printer setup I have selected the paper size and types to Auto and unspecified.

    So in PrintRequestAttributes or DocPrintJobAttributes how do I make sure
    my print job is not trying to override the default paper type?


  2. #2
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,661
    Thanks
    25
    Thanked 325 Times in 302 Posts

    Default Re: javax.print setting attributes

    What if you do not include the line that says:
    preqats.add(MediaSizeName.ISO_A4);

    I'm just guessing, but maybe it thinks you are trying to override the paper type simply because you specified the paper type. If you don't specify the printing type (and it still works), it should logically use the printer's default paper type.

    Give it a try and tell me what happens.


    EDIT: I suspect this is happening. If you read the API for MediaSizeName (MediaSizeName (Java Platform SE 6)), it reads:
    This attribute can be used instead of specifying MediaName or MediaTray.
    Since you are specifying the MediaTray, you should not have to specify the MediaSizeName.
    Last edited by aussiemcgr; February 3rd, 2011 at 04:35 PM.
    NOTE TO NEW PEOPLE LOOKING FOR HELP ON FORUM:

    When asking for help, please follow these guidelines to receive better and more prompt help:
    1. Put your code in Java Tags. To do this, put [highlight=java] before your code and [/highlight] after your code.
    2. Give full details of errors and provide us with as much information about the situation as possible.
    3. Give us an example of what the output should look like when done correctly.

    Join the Airline Management Simulation Game to manage your own airline against other users in a virtual recreation of the United States Airline Industry. For more details, visit: http://airlinegame.orgfree.com/

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

    Default Re: javax.print setting attributes

    Hi aussiemcgr,

    I have tried a few variations, with and without the attributes:

    PrintRequestAttributeSet preqats = new HashPrintRequestAttributeSet();
    preqats.add(new Copies(2));
    // Media Tray and MediaSizeName attributes are disabled to use the printer defaults
    // preqats.add(MediaTray.MAIN);
    //preqats.add(MediaSizeName.ISO_A4);

    Also tried adding
    preqats.add(MediaName.ISO_A4_WHITE);

    Also changed the paper type in the printer setup, so if the printer thinks I'm sending a plain paper print request, and it has plain paper in stock, it should go ahead and print.
    No success!
    If I open a standard cross platform printdialog from ServiceUI.printDialog there are no options for paper type.
    I do get these options in the Windows native dialog if I print from Adobe Reader. But I haven't seen any info on using platform native dialogs from javax.print, only from java.awt.print.
    Many thanks

Similar Threads

  1. Get CSS Attributes using Java
    By justinmifsud in forum Object Oriented Programming
    Replies: 2
    Last Post: February 15th, 2011, 04:08 PM
  2. Cannot access class attributes
    By Cyburg in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 29th, 2010, 07:30 AM
  3. Replies: 3
    Last Post: May 15th, 2010, 02:05 PM
  4. looping through an ArrayList of objects with their own attributes
    By etidd in forum Java Theory & Questions
    Replies: 2
    Last Post: April 2nd, 2010, 06:15 AM
  5. Javax.Mail Query Help Me Please
    By ravjot28 in forum What's Wrong With My Code?
    Replies: 10
    Last Post: January 19th, 2010, 10:06 AM