Example usage for java.awt.print Paper getWidth

List of usage examples for java.awt.print Paper getWidth

Introduction

In this page you can find the example usage for java.awt.print Paper getWidth.

Prototype

public double getWidth() 

Source Link

Document

Returns the width of the page in 1/72nds of an inch.

Usage

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    PrinterJob pj = PrinterJob.getPrinterJob();

    PageFormat pf = pj.defaultPage();
    Paper paper = new Paper();
    double margin = 36; // half inch
    paper.setImageableArea(margin, margin, paper.getWidth() - margin * 2, paper.getHeight() - margin * 2);
    pf.setPaper(paper);/*from w ww.ja  v a  2  s . co m*/

    pj.setPrintable(new MyPrintable(), pf);
    if (pj.printDialog()) {
        try {
            pj.print();
        } catch (PrinterException e) {
            System.out.println(e);
        }
    }
}

From source file:PageFormatFactory.java

/**
 * Logs the paper size./*from   w w  w.ja  v a2 s.  co m*/
 *
 * @param pf the paper size.
 */
public static void logPaper(final Paper pf) {
    System.out.println("Paper: Width: " + pf.getWidth() + " Height: " + pf.getHeight());
    System.out.println("Paper: Image: X " + pf.getImageableX() + " Y " + pf.getImageableY() + " H: "
            + pf.getImageableHeight() + " W: " + pf.getImageableWidth());
}

From source file:PageFormatFactory.java

/**
 * Tests, whether the given two page format objects are equal.
 *
 * @param pf1 the first page format that should be compared.
 * @param pf2 the second page format that should be compared.
 * @return true, if both page formats are equal, false otherwise.
 *///from  w w  w.  j  a v  a  2  s  . c  o m
public static boolean isEqual(final PageFormat pf1, final PageFormat pf2) {
    if (pf1 == pf2) {
        return true;
    }
    if (pf1 == null || pf2 == null) {
        return false;
    }

    if (pf1.getOrientation() != pf2.getOrientation()) {
        return false;
    }
    final Paper p1 = pf1.getPaper();
    final Paper p2 = pf2.getPaper();

    if (p1.getWidth() != p2.getWidth()) {
        return false;
    }
    if (p1.getHeight() != p2.getHeight()) {
        return false;
    }
    if (p1.getImageableX() != p2.getImageableX()) {
        return false;
    }
    if (p1.getImageableY() != p2.getImageableY()) {
        return false;
    }
    if (p1.getImageableWidth() != p2.getImageableWidth()) {
        return false;
    }
    if (p1.getImageableHeight() != p2.getImageableHeight()) {
        return false;
    }
    return true;
}

From source file:PageFormatFactory.java

/**
 * Returns the right border of the given paper.
 *
 * @param p the paper that defines the borders.
 * @return the right border./*ww w .j a  v a 2  s  . c  o  m*/
 */
public double getRightBorder(final Paper p) {
    return p.getWidth() - (p.getImageableX() + p.getImageableWidth());
}

From source file:PageFormatFactory.java

/**
 * 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.
 * @deprecated This functionality is part of JCommon-Serializer
 *//*from   w ww.  j a va2s. c o  m*/
public 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 };
}

From source file:PageFormatFactory.java

/**
 * Defines the imageable area of the given paper by adjusting the border around the imagable area. The bordersizes are
 * given in points./*from  ww  w  .j ava  2s. c  om*/
 *
 * @param paper  the paper that should be modified
 * @param top    the bordersize of the top-border
 * @param left   the border in points in the left
 * @param bottom the border in points in the bottom
 * @param right  the border in points in the right
 */
public void setBorders(final Paper paper, final double top, final double left, final double bottom,
        final double right) {
    final double w = paper.getWidth() - (right + left);
    final double h = paper.getHeight() - (bottom + top);
    paper.setImageableArea(left, top, w, h);
}

From source file:org.pentaho.reporting.engine.classic.core.util.PageFormatFactory.java

private static String printPaper(final Paper paper) {
    StringBuffer b = new StringBuffer();
    b.append("Paper={width=");
    b.append(paper.getWidth());
    b.append(", height=");
    b.append(paper.getHeight());/*from  w w w .  j a va2 s . c  o  m*/
    b.append(", imageableX=");
    b.append(paper.getImageableX());
    b.append(", imageableY=");
    b.append(paper.getImageableY());
    b.append(", imageableWidth=");
    b.append(paper.getImageableWidth());
    b.append(", imageableHeight=");
    b.append(paper.getImageableHeight());
    b.append("}");
    return b.toString();
}

From source file:org.pentaho.reporting.engine.classic.extensions.modules.java14print.Java14PrintUtil.java

/**
 * This method replaces the media definition from the given attribute set with the one found in the report itself.
 * <p/>/*from   ww w. j a  v  a2s.c  o m*/
 * If no JobName is set, a default jobname will be assigned.
 *
 * @param attributes
 * @param report
 * @return
 */
public static PrintRequestAttributeSet copyConfiguration(PrintRequestAttributeSet attributes,
        final MasterReport report) {
    if (attributes == null) {
        attributes = new HashPrintRequestAttributeSet();
    }

    // for now, be lazy, assume that the first page is the reference
    final PageDefinition pdef = report.getPageDefinition();
    final PageFormat format = pdef.getPageFormat(0);
    final Paper paper = format.getPaper();

    final Media media = MediaSize.findMedia((float) (paper.getWidth() / POINTS_PER_INCH),
            (float) (paper.getHeight() / POINTS_PER_INCH), Size2DSyntax.INCH);
    attributes.add(media);

    final MediaPrintableArea printableArea = new MediaPrintableArea(
            (float) (paper.getImageableX() / POINTS_PER_INCH),
            (float) (paper.getImageableY() / POINTS_PER_INCH),
            (float) (paper.getImageableWidth() / POINTS_PER_INCH),
            (float) (paper.getImageableHeight() / POINTS_PER_INCH), Size2DSyntax.INCH);

    attributes.add(printableArea);
    attributes.add(mapOrientation(format.getOrientation()));

    return attributes;
}

From source file:org.saiku.adhoc.utils.TemplateUtils.java

public static void mergePageSetup(SaikuMasterModel model, MasterReport output) {

    Paper paper = null;
    SaikuReportSettings settings = model.getSettings();

    if (settings.getPageFormat() == null) {
        paper = output.getPageDefinition().getPageFormat(0).getPaper();
        settings.setPageFormat(/*w w  w  .  j  ava  2  s. com*/
                PageFormatFactory.getInstance().getPageFormatName(paper.getWidth(), paper.getHeight()));
    } else {
        paper = PageFormatFactory.getInstance().createPaper(settings.getPageFormat());
    }

    PageFormat pageFormat = null;
    if (settings.getOrientation() == null) {
        settings.setOrientation(output.getPageDefinition().getPageFormat(0).getOrientation());
        pageFormat = output.getPageDefinition().getPageFormat(0);
    } else {
        int orientation = settings.getOrientation();
        pageFormat = PageFormatFactory.getInstance().createPageFormat(paper, orientation);
    }

    if (settings.getMarginBottom() == null || settings.getMarginLeft() == null
            || settings.getMarginRight() == null || settings.getMarginTop() == null) {
        Insets insets = PageFormatFactory.getInstance()
                .getPageMargins(output.getPageDefinition().getPageFormat(0));
        settings.setMarginBottom(insets.bottom);
        settings.setMarginLeft(insets.left);
        settings.setMarginTop(insets.top);
        settings.setMarginRight(insets.right);
    } else {
        Insets insets = new Insets(settings.getMarginTop(), settings.getMarginLeft(),
                settings.getMarginBottom(), settings.getMarginRight());
        PageFormatFactory.getInstance().setPageMargins(pageFormat, insets);
    }

    PageDefinition format = new SimplePageDefinition(pageFormat);
    output.setPageDefinition(format);

}

From source file:org.saiku.reporting.core.builder.MergeFormatUtil.java

public static void mergePageSetup(ReportSpecification model, MasterReport output) {

    Paper paper = null;

    PageSetup settings = model.getPageSetup();

    if (settings.getPageFormat() == null) {
        paper = output.getPageDefinition().getPageFormat(0).getPaper();
        settings.setPageFormat(//from w  w  w  .  j av a  2  s.c o m
                PageFormatFactory.getInstance().getPageFormatName(paper.getWidth(), paper.getHeight()));
    } else {
        paper = PageFormatFactory.getInstance().createPaper(settings.getPageFormat());
    }

    PageFormat pageFormat = null;
    if (settings.getPageOrientation() == null) {
        settings.setPageOrientation(output.getPageDefinition().getPageFormat(0).getOrientation());
        pageFormat = output.getPageDefinition().getPageFormat(0);
    } else {
        int orientation = settings.getPageOrientation();
        pageFormat = PageFormatFactory.getInstance().createPageFormat(paper, orientation);
    }

    if (settings.getBottomMargin() == null || settings.getLeftMargin() == null
            || settings.getRightMargin() == null || settings.getTopMargin() == null) {
        Insets insets = PageFormatFactory.getInstance()
                .getPageMargins(output.getPageDefinition().getPageFormat(0));
        settings.setBottomMargin(insets.bottom);
        settings.setLeftMargin(insets.left);
        settings.setTopMargin(insets.top);
        settings.setRightMargin(insets.right);
    } else {
        Insets insets = new Insets(settings.getTopMargin(), settings.getLeftMargin(),
                settings.getBottomMargin(), settings.getRightMargin());
        PageFormatFactory.getInstance().setPageMargins(pageFormat, insets);
    }

    PageDefinition format = new SimplePageDefinition(pageFormat);
    output.setPageDefinition(format);

}