How to set PrinterResolution with using java.awt.Print.PrintJob object

Posted on 2006-06-07
Last Modified: 2008-01-16

Hi Experts
I have used java.awt.Print.PrintJob and PageFormat object to develop a print java app

But I want to set printer resolution when I print.

How can to do this, please help me!

Thank in advance!
Question by:CongUan
    LVL 92

    Accepted Solution

    you need to scale the graphics context you use to print to.
    see the section on nbottom that talks about units of measurement

    Author Comment

    Scaling image is not good in this case, It maybe have problem with the image,

    As the java.awt.PrintJob I know that we can set the print resolution by the below code
         //set resoltion for print
        java.awt.PageAttributes pa= new PageAttributes();
        // get printer job
        java.awt.PrintJob pj=Toolkit.getDefaultToolkit().getPrintJob(this,"My Printing",null,pa);

    But I have not used. I used java.awt.Print.PrintJob to develop,
    So, do we have any way to do with java.awt.Print.PrintJob for setting the resolution?

    Thank again!
    LVL 92

    Expert Comment

    not the image, the graphics context you are printing to.

    Author Comment

    I am not clearly about your mention, what is graphics context related here?

    LVL 92

    Expert Comment

    The Graphics instance passed to your print() method.
    LVL 14

    Assisted Solution


    Author Comment

    Thank hoomany,
    It is very helpful for me!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
    Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
    Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now