Good, so I just started working on a program that was forced to print my graphics. Mine is almost identical to copyrighted in Oracle located here http://docs.oracle.com/javase/tutorial/2d/printing/examples/HelloWorldPrinter.java
So basically Iβm a complete noob and tried to figure out how to set my page to 8.5x11in and 300dpi, but to no avail :( I donβt even have working code in this thread after all the failed attempts. I know that it has something to do with
Paper.setSize() and
PrinterResolution But I cannot extract from javadocs correctly to understand them. Please help.
EDIT: I believe that I found that Paper.setSize(72*8.5,72*11); Sets the page size to 8.5x11, but the dpi is still 72. For now, this is my code.
public int print(Graphics g, PageFormat pf, int page) throws PrinterException { Graphics2D g2d = (Graphics2D)g; g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); Paper pg = new Paper(); pg.setSize(72*8.5,72*11); pf.setPaper(pg); if (page > 0) { return NO_SUCH_PAGE; }
source share