Refine search
public void printComponenet(){ PrinterJob pj = PrinterJob.getPrinterJob(); pj.setJobName(" Print Component "); pj.setPrintable (new Printable() { public int print(Graphics pg, PageFormat pf, int pageNum){ if (pageNum > 0){ return Printable.NO_SUCH_PAGE; } Graphics2D g2 = (Graphics2D) pg; g2.translate(pf.getImageableX(), pf.getImageableY()); componenet_name.paint(g2); return Printable.PAGE_EXISTS; } }); if (pj.printDialog() == false) return; try { pj.print(); } catch (PrinterException ex) { // handle exception } }
if (pageIndex == 0) { graphics.translate((int)pageFormat.getImageableX(), (int)pageFormat.getImageableY());
int x = (int)pageFormat.getImageableX(); int y = (int)pageFormat.getImageableY();
xOffset = (int)pageFormat.getImageableX(); int y = (int)pageFormat.getImageableY() + fm.getAscent() + 1;
xOffset = (int)pageFormat.getImageableX(); int y = (int)pageFormat.getImageableY() + fm.getAscent() + 1;
public class HTMLPrinter implements Printable{ private final JEditorPane printPane; public HTMLPrinter(JEditorPane editorPane){ printPane = editorPane; } public int print(Graphics graphics, PageFormat pageFormat, int pageIndex){ if (pageIndex >= 1) return Printable.NO_SUCH_PAGE; Graphics2D g2d = (Graphics2D)graphics; g2d.setClip(0, 0, (int)pageFormat.getImageableWidth(), (int)pageFormat.getImageableHeight()); g2d.translate((int)pageFormat.getImageableX(), (int)pageFormat.getImageableY()); RepaintManager rm = RepaintManager.currentManager(printPane); boolean doubleBuffer = rm.isDoubleBufferingEnabled(); rm.setDoubleBufferingEnabled(false); printPane.setSize((int)pageFormat.getImageableWidth(), 1); printPane.print(g2d); rm.setDoubleBufferingEnabled(doubleBuffer); return Printable.PAGE_EXISTS; } }
graphics2D.translate(pageFormat.getImageableX(), pageFormat.getImageableY());
double width = pageFormat.getImageableWidth(); double height = pageFormat.getImageableHeight(); g2d.translate((int) pageFormat.getImageableX(), (int) pageFormat.getImageableY()); g2d.draw(new Rectangle2D.Double(1, 1, width - 1, height - 1)); FontMetrics fm = g2d.getFontMetrics();
xOffset = (int)pageFormat.getImageableX(); int y = (int)pageFormat.getImageableY() + fm.getAscent() + 1;
public int print(Graphics g, PageFormat pf, int i) throws PrinterException { if (i > getPrintableImages(pf).size() - 1) { //returning this stops printing 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());
public RenderNode[] getNodesAt( final double x, final double y, final double width, final double height, final String namespace, final String name ) { return pageDrawable.getNodesAt( x - pageFormat.getImageableX(), y - pageFormat.getImageableY(), width, height, namespace, name ); }
public int print(Graphics g, PageFormat pageFormat, int pageIndex) { if (pageIndex > 0) return NO_SUCH_PAGE; g.translate((int)pageFormat.getImageableX(), (int)pageFormat.getImageableY()); mComponent.paintComponent(g); return PAGE_EXISTS; } }
public int print(Graphics g, PageFormat pf, int page) throws PrinterException { Graphics2D g2 = (Graphics2D) g; if (page > pageCount) return Printable.NO_SUCH_PAGE; g2.translate(pf.getImageableX(), pf.getImageableY()); drawPage(g2, pf, page); return Printable.PAGE_EXISTS; }
/** * Appelle la methode initGraphics(_g), translate l'origine sur le coin superieur gauche imprimable de _format puis * retourne les coordonnees de ce point. * * @param _format le PageFormat a respecter. * @param _g2d * @return les coordonnees du coin superieur gauche de la zone imprimable. */ public static double[] initGraphics(final Graphics2D _g2d, final PageFormat _format) { initGraphics(_g2d); final double x = _format.getImageableX(); final double y = _format.getImageableY(); _g2d.translate(x, y); return new double[] { x, y }; }
public RenderNode[] getNodesAt( final double x, final double y, final String namespace, final String name ) { return pageDrawable.getNodesAt( x - pageFormat.getImageableX(), y - pageFormat.getImageableY(), namespace, name ); }
@Override final public int print( final Graphics g, final PageFormat page_format, final int page_index ) throws PrinterException { if ( page_index > 0 ) { return ( NO_SUCH_PAGE ); } else { final Graphics2D g2d = ( Graphics2D ) g; g2d.translate( page_format.getImageableX(), page_format.getImageableY() ); // Turn off double buffering !? paintPhylogeny( g2d, true, false, 0, 0, 0, 0 ); // Turn double buffering back on !? return ( PAGE_EXISTS ); } }
/** * Prints this panel on a single page. * <p> * {@inheritDoc} */ @Override public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) { if (pageIndex > 0) { return(NO_SUCH_PAGE); } else { graphics.translate((int)pageFormat.getImageableX(), (int)pageFormat.getImageableY()); print(graphics); return(PAGE_EXISTS); } }
public class CustomTablePrintable implements Printable { Printable tablePrintable; public void setTablePrintable(Printable printable) { tablePrintable = printable; } public int print(Graphics graphics, PageFormat pageFormat, int pageIndex) throws PrinterException { if (pageIndex > 0) { return NO_SUCH_PAGE; } tablePrintable.print(graphics, pageFormat, pageIndex); Graphics2D g2d = (Graphics2D)graphics; g2d.translate(pageFormat.getImageableX(), pageFormat.getImageableY()); // Draw header/footer here graphics.drawString(header, posx, posy); return PAGE_EXISTS; } }
public Insets getPageMargins( final PageFormat format ) { final int marginLeft = (int) format.getImageableX(); final int marginRight = (int) ( format.getWidth() - format.getImageableWidth() - format.getImageableX() ); final int marginTop = (int) ( format.getImageableY() ); final int marginBottom = (int) ( format.getHeight() - format.getImageableHeight() - format.getImageableY() ); return new Insets( marginTop, marginLeft, marginBottom, marginRight ); }
public int print(Graphics pg, PageFormat pf, int pageNum) { if (page > 0) { return NO_SUCH_PAGE; } Graphics2D g2d = (Graphics2D)pg; double pageWidth = pf.getImageableWidth(); double pageHeight = pf.getImageableHeight(); double pageX = pf.getImageableX(); double pageY = pf.getImageableY(); g2d.translate(pageX, pageY); double tableHeight = pageHeight / 2d; jPanel1.setBounds(0, 0, (int)Math.floor(pageWidth), (int)Math.floor(pageHeight)); jPanel1.printAll(g2d); return Printable.PAGE_EXISTS; }