Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2009
    Rep Power

    Post Printing JPEG file using java

    hi friends,
    I Have to print a jpeg file situated on my system using java..can anyone please tell me how to do that..

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Rep Power

  3. #3
    toadaly is offline Senior Member
    Join Date
    Jan 2009
    Rep Power


    Well, here are the steps:

    1. load the file using javax.imageio.ImagIO. This will give you a BufferedImage. Suppose you had called that BufferedImage "bufferedImage".
    2. Use the print API

    cut/paste from the print tutorial, with slight modification

    Java Code:
    import java.awt.print.*;
    import java.awt.*;
    public class HelloWorldPrinter implements Printable {
      public int print(Graphics g, PageFormat pf, int page) throws
                                                            PrinterException {
        if (page > 0) { /* We have only one page, and 'page' is zero-based */
             return NO_SUCH_PAGE;
        /* User (0,0) is typically outside the imageable area, so we must
         * translate by the X and Y values in the PageFormat to avoid clipping
        Graphics2D g2d = (Graphics2D)g;
        g2d.translate(pf.getImageableX(), pf.getImageableY());
        /* Now we perform our rendering */
        g.drawImage(bufferedImage, 0, 0, null);
        /* tell the caller that this page is part of the printed document */
        return PAGE_EXISTS;

Similar Threads

  1. Sorting and Printing file
    By spry.chipper in forum New To Java
    Replies: 3
    Last Post: 12-13-2009, 09:15 PM
  2. Creating a jpeg file: "no preview available"
    By ScottVal in forum Advanced Java
    Replies: 1
    Last Post: 10-24-2009, 04:31 AM
  3. how to include restart merkers in a JPEG file
    By ananta_javaforums001 in forum Networking
    Replies: 0
    Last Post: 04-09-2009, 04:29 PM
  4. Job name when printing file
    By pjmorce in forum Advanced Java
    Replies: 3
    Last Post: 12-23-2008, 02:55 AM
  5. To open an image file such as Jpeg file using JAva Program
    By itmani2020 in forum Advanced Java
    Replies: 10
    Last Post: 07-11-2008, 10:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts