Results 1 to 3 of 3
Thread: Printing JPEG file using java
- 02-17-2010, 07:34 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 16
- Rep Power
- 0
- 02-17-2010, 09:27 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
- 02-18-2010, 05:50 AM #3
Senior Member
- Join Date
- Jan 2009
- Posts
- 671
- Rep Power
- 5
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
-
Sorting and Printing file
By spry.chipper in forum New To JavaReplies: 3Last Post: 12-13-2009, 08:15 PM -
Creating a jpeg file: "no preview available"
By ScottVal in forum Advanced JavaReplies: 1Last Post: 10-24-2009, 03:31 AM -
how to include restart merkers in a JPEG file
By ananta_javaforums001 in forum NetworkingReplies: 0Last Post: 04-09-2009, 03:29 PM -
Job name when printing file
By pjmorce in forum Advanced JavaReplies: 3Last Post: 12-23-2008, 01:55 AM -
To open an image file such as Jpeg file using JAva Program
By itmani2020 in forum Advanced JavaReplies: 10Last Post: 07-11-2008, 09:57 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks