Example usage for javax.print.attribute.standard MediaSize findMedia

List of usage examples for javax.print.attribute.standard MediaSize findMedia

Introduction

In this page you can find the example usage for javax.print.attribute.standard MediaSize findMedia.

Prototype

public static MediaSizeName findMedia(float x, float y, int units) 

Source Link

Document

The specified dimensions are used to locate a matching MediaSize instance from amongst all the standard MediaSize instances.

Usage

From source file:org.openvpms.archetype.rules.doc.DocumentTemplate.java

/**
 * Helper to convert a custom paper size to a {@link MediaSizeName}.
 *
 * @param width  the page width/*ww w.j av  a 2 s  . c  o  m*/
 * @param height the page height
 * @param units  the units. One of 'MM' or 'INCH'.
 * @return the corresponding media size name.
 * @throws DocumentException if the paper size is invalid
 */
private MediaSizeName getMedia(BigDecimal width, BigDecimal height, String units) {
    int unitCode = Units.getUnits(units);
    try {
        return MediaSize.findMedia(width.floatValue(), height.floatValue(), unitCode);
    } catch (IllegalArgumentException exception) {
        String size = width + "x" + height + " " + units;
        throw new DocumentException(InvalidPaperSize, size);
    }
}

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 ava 2  s.  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;
}