import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.print.PageFormat; import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; @Aspect public class JRMinoltaAspect { @Before("execution(int net.sf.jasperreports.engine.print.JRPrinterAWT.print(java.awt.Graphics, java.awt.print.PageFormat , int )) && args(g, pf, ..)") public void scalePrint(Graphics g, PageFormat pf){ if(pf.getOrientation() == PageFormat.LANDSCAPE){ g.translate(0, (int)pf.getHeight() / 2 ); } ((Graphics2D)g).scale(0.5, 0.5); } }
public void pageDialog() { this.pageFormat = getPrinterJob().pageDialog(getPageFormat()); Paper paper = pageFormat.getPaper(); StringBuilder sb = new StringBuilder(); NumberFormat format = DecimalFormat.getInstance(Locale.US); double paperWidth = paper.getWidth(); sb.append(format.format(paperWidth)).append(' '); double paperHeight = paper.getHeight(); sb.append(format.format(paperHeight)).append(' '); double imageableX = paper.getImageableX(); sb.append(format.format(imageableX)).append(' '); double imageableY = paper.getImageableY(); sb.append(format.format(imageableY)).append(' '); double imageableWidth = paper.getImageableWidth(); sb.append(format.format(imageableWidth)).append(' '); double imageableHeight = paper.getImageableHeight(); sb.append(format.format(imageableHeight)).append(' '); int pageFormatOrientation = pageFormat.getOrientation(); sb.append(format.format(pageFormatOrientation)).append(' '); ResourceController.getResourceController().setProperty("pageSettings", sb.toString()); }
/** * Adjusts the graphics context according to the given format.<br> * * The job can be printed in two ways: by job.print() and by job.print(aset). * The latter analyzes the aset, builds a pageformat and transforms the graphics-context accordingly. * However, the first variant does not, i.e. if the pageformat returned by print(job, jobname) above * is *not* PORTRAIT, the graphics context still has to be transformed and the page-dimensions * changed. * * @param g the graphics context * @param format the pageformat * @return true if transformation adjusted, else false */ public static boolean adjustGraphics2D(Graphics2D g, PageFormat format) { if (format.getOrientation() != PageFormat.PORTRAIT) { // check if transformation necessary AffineTransform oldTransform = g.getTransform(); if ((oldTransform.getType() & AffineTransform.TYPE_QUADRANT_ROTATION) == 0) { g.setTransform(new AffineTransform(format.getMatrix())); } } return false; }
public static String printPageFormat( final PageFormat pf ) { StringBuffer b = new StringBuffer(); b.append( "PageFormat={width=" ); b.append( pf.getWidth() ); b.append( ", height=" ); b.append( pf.getHeight() ); b.append( ", imageableX=" ); b.append( pf.getImageableX() ); b.append( ", imageableY=" ); b.append( pf.getImageableY() ); b.append( ", imageableWidth=" ); b.append( pf.getImageableWidth() ); b.append( ", imageableHeight=" ); b.append( pf.getImageableHeight() ); b.append( ", orientation=" ).append( pf.getOrientation() ); b.append( ", paper=" ); b.append( printPaper( pf.getPaper() ) ); b.append( "}" ); return b.toString(); }
public static void printPageFormat(PageFormat pf) { System.out.println("paper size:" + pf.getWidth() + "x" + pf.getHeight() + " orientation:" + pf.getOrientation()); System.out.println("imageable position: X=" + pf.getImageableX() + " Y=" + pf.getImageableY()); System.out.println("imageable size:" + pf.getImageableWidth() + "x" + pf.getImageableHeight()); }
/** Patch for a bug in the PageFormat class * @param pf PageFormat * @return imageable y coordination for this page format */ private float getImageableYPatch(PageFormat pf) { if (pf.getOrientation() == PageFormat.LANDSCAPE) { double ret = pf.getPaper().getWidth() - (pf.getImageableY() + pf.getImageableHeight()); return (float) Math.round(ret); } else { return (float) pf.getImageableY(); } }
/** Patch for a bug in the PageFormat class * @param pf PageFormat * @return imageable x coordination for this page format */ private float getImageableXPatch(PageFormat pf) { if (pf.getOrientation() == PageFormat.LANDSCAPE) { double ret = pf.getPaper().getHeight() - (pf.getImageableX() + pf.getImageableWidth()); return (float) Math.round(ret); } else { return (float) pf.getImageableX(); } }
/** Patch for a bug in the PageFormat class * @param pf PageFormat * @return imageable x coordination for this page format */ private float getImageableXPatch(PageFormat pf) { if (pf.getOrientation() == PageFormat.LANDSCAPE) { double ret = pf.getPaper().getHeight() - (pf.getImageableX() + pf.getImageableWidth()); return (float) Math.round(ret); } else { return (float) pf.getImageableX(); } }
/** Patch for a bug in the PageFormat class * @param pf PageFormat * @return imageable x coordination for this page format */ private float getImageableXPatch(PageFormat pf) { if (pf.getOrientation() == PageFormat.LANDSCAPE) { double ret = pf.getPaper().getHeight() - (pf.getImageableX() + pf.getImageableWidth()); return (float) Math.round(ret); } else { return (float) pf.getImageableX(); } }
/** Patch for a bug in the PageFormat class * @param pf PageFormat * @return imageable y coordination for this page format */ private float getImageableYPatch(PageFormat pf) { if (pf.getOrientation() == PageFormat.LANDSCAPE) { double ret = pf.getPaper().getWidth() - (pf.getImageableY() + pf.getImageableHeight()); return (float) Math.round(ret); } else { return (float) pf.getImageableY(); } }
/** Patch for a bug in the PageFormat class * @param pf PageFormat * @return imageable y coordination for this page format */ private float getImageableYPatch(PageFormat pf) { if (pf.getOrientation() == PageFormat.LANDSCAPE) { double ret = pf.getPaper().getWidth() - (pf.getImageableY() + pf.getImageableHeight()); return (float) Math.round(ret); } else { return (float) pf.getImageableY(); } }
/** * Resolves a page format, so that the result can be serialized. * * @param format the page format that should be prepared for serialisation. * @return the prepared page format data. */ private Object[] resolvePageFormat( final PageFormat format ) { final Integer orientation = new Integer( format.getOrientation() ); final Paper p = format.getPaper(); final float[] fdim = new float[] { (float) p.getWidth(), (float) p.getHeight() }; final float[] rect = new float[] { (float) p.getImageableX(), (float) p.getImageableY(), (float) p.getImageableWidth(), (float) p.getImageableHeight() }; return new Object[] { orientation, fdim, rect }; }
/** Writes a PageFormat instance into ObjectOutput * @param pf * @param obtos */ private static void externalizePageFormat(PageFormat pf, ObjectOutput obtos) throws IOException { if (pf == null) { obtos.writeInt(PageFormat.LANDSCAPE ^ PageFormat.REVERSE_LANDSCAPE ^ PageFormat.PORTRAIT); return; } obtos.writeInt(pf.getOrientation()); Paper paper = pf.getPaper(); // paper size obtos.writeDouble(paper.getWidth()); obtos.writeDouble(paper.getHeight()); // paper imageable area obtos.writeDouble(paper.getImageableX()); obtos.writeDouble(paper.getImageableY()); obtos.writeDouble(paper.getImageableWidth()); obtos.writeDouble(paper.getImageableHeight()); }
/** Writes a PageFormat instance into ObjectOutput * @param pf * @param obtos */ private static void externalizePageFormat(PageFormat pf, ObjectOutput obtos) throws IOException { if (pf == null) { obtos.writeInt(PageFormat.LANDSCAPE ^ PageFormat.REVERSE_LANDSCAPE ^ PageFormat.PORTRAIT); return; } obtos.writeInt(pf.getOrientation()); Paper paper = pf.getPaper(); // paper size obtos.writeDouble(paper.getWidth()); obtos.writeDouble(paper.getHeight()); // paper imageable area obtos.writeDouble(paper.getImageableX()); obtos.writeDouble(paper.getImageableY()); obtos.writeDouble(paper.getImageableWidth()); obtos.writeDouble(paper.getImageableHeight()); }
public PhysicalPageBox( final PageFormat pageFormat, final long globalX, final long globalY ) { this.width = StrictGeomUtility.toInternalValue( pageFormat.getWidth() ); this.height = StrictGeomUtility.toInternalValue( pageFormat.getHeight() ); this.imageableX = StrictGeomUtility.toInternalValue( pageFormat.getImageableX() ); this.imageableY = StrictGeomUtility.toInternalValue( pageFormat.getImageableY() ); this.imageableWidth = StrictGeomUtility.toInternalValue( pageFormat.getImageableWidth() ); this.imageableHeight = StrictGeomUtility.toInternalValue( pageFormat.getImageableHeight() ); this.globalX = globalX; this.globalY = globalY; this.orientation = pageFormat.getOrientation(); }
/** * Renvoie le format en prenant en compte de la taille de l'entete et du pied de page. Les marges * "haut" et "bas" sont augmentees en fonction de la taille de l'entete et du pied de page. */ public PageFormat getDocumentPageFormat(final Graphics _g){ final PageFormat r = (PageFormat) pageFormat_.clone(); final int he = getHauteurEntete(_g); final int hp = getHauteurPied(_g); final double ixPF = r.getImageableX(); final double iyPF = r.getImageableY() + he; final double iwPF = r.getImageableWidth(); final double ihPF = r.getImageableHeight() - he - hp; final Paper p = r.getPaper(); if (r.getOrientation() == PageFormat.PORTRAIT) { p.setImageableArea(ixPF, iyPF, iwPF, ihPF); } else { p.setImageableArea(iyPF, ixPF, ihPF, iwPF); } r.setPaper(p); return r; }
/** * @param pf <code>PageFormat</code> that describes the size and * orientation of a page to be printed */ public static void setPageFormat(PageFormat pf) { getPreferences().putInt(PROP_PAGE_ORIENTATION, pf.getOrientation()); getPreferences().putDouble(PROP_PAGE_WIDTH, pf.getPaper().getWidth()); getPreferences().putDouble(PROP_PAGE_HEIGHT, pf.getPaper().getHeight()); getPreferences().putDouble(PROP_PAGE_IMAGEABLEAREA_WIDTH, pf.getPaper().getImageableWidth()); getPreferences().putDouble(PROP_PAGE_IMAGEABLEAREA_HEIGHT, pf.getPaper().getImageableHeight()); getPreferences().putDouble(PROP_PAGE_IMAGEABLEAREA_X, pf.getPaper().getImageableX()); getPreferences().putDouble(PROP_PAGE_IMAGEABLEAREA_Y, pf.getPaper().getImageableY()); }
public static void pageSetup(View view) { job = getPrintJob(); PageFormat newFormat = job.pageDialog(format); if(newFormat != null) { format = newFormat; jEdit.setIntegerProperty("print.orientation",format.getOrientation()); Paper paper=format.getPaper(); jEdit.setDoubleProperty("print.width",paper.getImageableWidth()); jEdit.setDoubleProperty("print.height",paper.getImageableHeight()); jEdit.setDoubleProperty("print.x",paper.getImageableX()); jEdit.setDoubleProperty("print.y",paper.getImageableY()); jEdit.setDoubleProperty("print.pagewidth",paper.getWidth()); jEdit.setDoubleProperty("print.pageheight",paper.getHeight()); } } //}}}
/** * Describes the physical output characteristics like page size, margins, and imaginable area. * * @return */ public PageFormat getPageFormat() { if ( pageDefinition == null ) { return new PageFormat(); } final PageFormat pageFormat = pageDefinition.getPageFormat(); final Paper orgPaper = pageFormat.getPaper(); final PageFormatFactory pff = PageFormatFactory.getInstance(); final double virtualPaperWidth = orgPaper.getImageableWidth() + pff.getLeftBorder( orgPaper ) + pff.getRightBorder( orgPaper ); final double virtualPaperHeight = orgPaper.getImageableHeight() + pff.getTopBorder( orgPaper ) + pff.getBottomBorder( orgPaper ); final Paper p = pff.createPaper( virtualPaperWidth, virtualPaperHeight ); pff.setBorders( p, pff.getTopBorder( orgPaper ), pff.getLeftBorder( orgPaper ), pff.getBottomBorder( orgPaper ), pff.getRightBorder( orgPaper ) ); return pff.createPageFormat( p, pageFormat.getOrientation() ); }
/** * Get an instance of {@link java.awt.print.PageFormat}. * @param pj {@link java.awt.print.PrinterJob} which is * associated with the default printer. * @return an instance of <code>PageFormat</code> that describes the size and * orientation of a page to be printed. */ public static PageFormat getPageFormat(PrinterJob pj) { PageFormat pageFormat = null; pageFormat = pj.defaultPage(); Paper p = pageFormat.getPaper(); int pageOrientation = getPreferences().getInt(PROP_PAGE_ORIENTATION, pageFormat.getOrientation()); double paperWidth = getPreferences().getDouble(PROP_PAGE_WIDTH, p.getWidth()); double paperHeight = getPreferences().getDouble(PROP_PAGE_HEIGHT, p.getHeight()); double iaWidth = getPreferences().getDouble(PROP_PAGE_IMAGEABLEAREA_WIDTH, p.getImageableWidth()); double iaHeight = getPreferences().getDouble(PROP_PAGE_IMAGEABLEAREA_HEIGHT, p.getImageableHeight()); double iaX = getPreferences().getDouble(PROP_PAGE_IMAGEABLEAREA_X, p.getImageableX()); double iaY = getPreferences().getDouble(PROP_PAGE_IMAGEABLEAREA_Y, p.getImageableY()); pageFormat.setOrientation(pageOrientation); p.setSize(paperWidth, paperHeight); p.setImageableArea(iaX, iaY, iaWidth, iaHeight); pageFormat.setPaper(p); return pageFormat; }