Drukowanie do twardej drukarki w java z 300dpi

Dobra, właśnie zacząłem pracować nad programem, który ma wydrukować jego grafikę. Mój jest prawie identyczny z chronionym prawem autorskim w Oracle znajdującym się tutajhttp://docs.oracle.com/javase/tutorial/2d/printing/examples/HelloWorldPrinter.java

Więc zasadniczo jestem kompletnym noobem i próbowałem dowiedzieć się, jak ustawić moją stronę na 8.5x11in i 300dpi, ale bezskutecznie :( Nie mam nawet działającego kodu na ten temat po wszystkich nieudanych próbach. robić zPaper.setSize() iPrinterResolution Ale javadocs nie potrafi zebrać wystarczającej ilości informacji, aby je zrozumieć. Proszę pomóż.

EDIT: Wierzę, że to odkryłemPaper.setSize(72*8.5,72*11); Ustawia rozmiar strony na 8,5 x 11, ale rozdzielczość nadal wynosi 72. To mój kod do tej pory.

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) { /* 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.drawString("Hello world! :D", 100, 100);

    /* tell the caller that this page is part of the printed document */
    return PAGE_EXISTS;
}

questionAnswers(1)

yourAnswerToTheQuestion