if (h * page > height) {   return Printable.NO_SUCH_PAGE; } int trans = (int) (-h * page);  g2.translate(0, trans);
    public int print(Graphics g, PageFormat pf, int page) {        try {            Graphics2D g2 = (Graphics2D) g;            double x = pf.getImageableX();            double y = pf.getImageableY();            double w = pf.getImageableWidth();            double h = pf.getImageableHeight();            g2.translate(x, y);                        //Uu.p("printing: page = " + page + " clip = " + g.getClipRect());                        //quit if this page would put us over the length of the document            if (h * page > height) {                //Uu.p("quitting: " + h*page);                //Uu.p("height = " + height);                return Printable.NO_SUCH_PAGE;            }            int trans = (int) (-h * page);            //Uu.p("translating by " + trans);            g2.translate(0, trans);                        // lay out the document if it's not already            if (g2r == null) {                //Uu.p("building new Graphics2DRenderer");                g2r = new Graphics2DRenderer();                g2r.getSharedContext().setPrint(true);                g2r.getSharedContext().setInteractive(false);                g2r.getSharedContext().setDPI(72f);                g2r.getSharedContext().getTextRenderer().setSmoothingThreshold(0);                g2r.getSharedContext().getTextRenderer().setSmoothingLevel(TextRenderer.HIGH);                g2r.setDocument(panel.getSharedContext().getUac().getBaseURL());                Dimension dim = new Dimension((int) w, (int) h);                g2r.layout(g2, dim);                Rectangle rect = g2r.getMinimumSize();                //Uu.p("laid out height = " + rect.getHeight());                height = (int) rect.getHeight();            }                        // render the document            g2r.render(g2);            return Printable.PAGE_EXISTS;        } catch (Exception ex) {            Uu.p(ex);            return Printable.NO_SUCH_PAGE;        }    }