Search in sources :

Example 6 with Paper

use of java.awt.print.Paper in project jdk8u_jdk by JetBrains.

the class RasterPrinterJob method validatePage.

/**
     * The passed in PageFormat is cloned and altered to be usable on
     * the PrinterJob's current printer.
     */
public PageFormat validatePage(PageFormat page) {
    PageFormat newPage = (PageFormat) page.clone();
    Paper newPaper = new Paper();
    validatePaper(newPage.getPaper(), newPaper);
    newPage.setPaper(newPaper);
    return newPage;
}
Also used : PageFormat(java.awt.print.PageFormat) Paper(java.awt.print.Paper)

Example 7 with Paper

use of java.awt.print.Paper in project jdk8u_jdk by JetBrains.

the class RasterPrinterJob method defaultPage.

/**
     * The passed in PageFormat will be copied and altered to describe
     * the default page size and orientation of the PrinterJob's
     * current printer.
     * Platform subclasses which can access the actual default paper size
     * for a printer may override this method.
     */
public PageFormat defaultPage(PageFormat page) {
    PageFormat newPage = (PageFormat) page.clone();
    newPage.setOrientation(PageFormat.PORTRAIT);
    Paper newPaper = new Paper();
    double ptsPerInch = 72.0;
    double w, h;
    Media media = null;
    PrintService service = getPrintService();
    if (service != null) {
        MediaSize size;
        media = (Media) service.getDefaultAttributeValue(Media.class);
        if (media instanceof MediaSizeName && ((size = MediaSize.getMediaSizeForName((MediaSizeName) media)) != null)) {
            w = size.getX(MediaSize.INCH) * ptsPerInch;
            h = size.getY(MediaSize.INCH) * ptsPerInch;
            newPaper.setSize(w, h);
            newPaper.setImageableArea(ptsPerInch, ptsPerInch, w - 2.0 * ptsPerInch, h - 2.0 * ptsPerInch);
            newPage.setPaper(newPaper);
            return newPage;
        }
    }
    /* Default to A4 paper outside North America.
         */
    String defaultCountry = Locale.getDefault().getCountry();
    if (// ie "C"
    !Locale.getDefault().equals(Locale.ENGLISH) && defaultCountry != null && !defaultCountry.equals(Locale.US.getCountry()) && !defaultCountry.equals(Locale.CANADA.getCountry())) {
        double mmPerInch = 25.4;
        w = Math.rint((210.0 * ptsPerInch) / mmPerInch);
        h = Math.rint((297.0 * ptsPerInch) / mmPerInch);
        newPaper.setSize(w, h);
        newPaper.setImageableArea(ptsPerInch, ptsPerInch, w - 2.0 * ptsPerInch, h - 2.0 * ptsPerInch);
    }
    newPage.setPaper(newPaper);
    return newPage;
}
Also used : PageFormat(java.awt.print.PageFormat) MediaSize(javax.print.attribute.standard.MediaSize) MediaSizeName(javax.print.attribute.standard.MediaSizeName) Media(javax.print.attribute.standard.Media) Paper(java.awt.print.Paper) PrintService(javax.print.PrintService) StreamPrintService(javax.print.StreamPrintService)

Example 8 with Paper

use of java.awt.print.Paper in project jgnash by ccavanaugh.

the class ReportPrintFactory method getPageFormat.

static PageFormat getPageFormat(final BaseDynamicJasperReport report) {
    Preferences p = report.getPreferences();
    double height = p.getDouble(HEIGHT, 0);
    double width = p.getDouble(WIDTH, 0);
    int orientation = p.getInt(ORIENTATION, 0);
    double imageableHeight = p.getDouble(IMAGEABLE_HEIGHT, 0);
    double imageableWidth = p.getDouble(IMAGEABLE_WIDTH, 0);
    double imageableX = p.getDouble(IMAGEABLE_X, 0);
    double imageableY = p.getDouble(IMAGEABLE_Y, 0);
    if (height == 0 || width == 0 || imageableHeight == 0 || imageableWidth == 0) {
        return getDefaultPage();
    }
    PrinterJob job = PrinterJob.getPrinterJob();
    PageFormat pf = job.defaultPage();
    pf.setOrientation(orientation);
    Paper paper = pf.getPaper();
    paper.setSize(width, height);
    paper.setImageableArea(imageableX, imageableY, imageableWidth, imageableHeight);
    pf.setPaper(paper);
    return pf;
}
Also used : PageFormat(java.awt.print.PageFormat) Paper(java.awt.print.Paper) Preferences(java.util.prefs.Preferences) PrinterJob(java.awt.print.PrinterJob)

Example 9 with Paper

use of java.awt.print.Paper in project jgnash by ccavanaugh.

the class ReportPrintFactory method savePageFormat.

/**
     * Save a {@code PageFormat} to preferences
     * 
     * @param report report
     * @param format {@code PageFormat} to save
     */
static void savePageFormat(final BaseDynamicJasperReport report, final PageFormat format) {
    Preferences p = report.getPreferences();
    p.putInt(ORIENTATION, format.getOrientation());
    Paper paper = format.getPaper();
    p.putDouble(HEIGHT, paper.getHeight());
    p.putDouble(WIDTH, paper.getWidth());
    p.putDouble(IMAGEABLE_HEIGHT, paper.getImageableHeight());
    p.putDouble(IMAGEABLE_WIDTH, paper.getImageableWidth());
    p.putDouble(IMAGEABLE_X, paper.getImageableX());
    p.putDouble(IMAGEABLE_Y, paper.getImageableY());
}
Also used : Paper(java.awt.print.Paper) Preferences(java.util.prefs.Preferences)

Example 10 with Paper

use of java.awt.print.Paper in project jgnash by ccavanaugh.

the class ReportPrintFactory method getDefaultPage.

/**
     * Returns the default paper size for a report
     * 
     * @return page format
     */
private static PageFormat getDefaultPage() {
    /* A4 is the assumed default */
    MediaSize defaultMediaSize = MediaSize.ISO.A4;
    /* US and Canada use letter size as the default */
    Locale[] letterLocales = new Locale[] { Locale.US, Locale.CANADA, Locale.CANADA_FRENCH };
    if (Arrays.asList(letterLocales).contains(Locale.getDefault())) {
        defaultMediaSize = MediaSize.NA.LETTER;
    }
    /* Create the default paper size with a default margin */
    Paper paper = new Paper();
    int width = (int) (defaultMediaSize.getX(MediaSize.INCH) / (1f / 72f));
    int height = (int) (defaultMediaSize.getY(MediaSize.INCH) / (1f / 72f));
    paper.setSize(width, height);
    paper.setImageableArea(DEFAULT_MARGIN, DEFAULT_MARGIN, width - (2 * DEFAULT_MARGIN), height - (2 * DEFAULT_MARGIN));
    PageFormat format = new PageFormat();
    format.setPaper(paper);
    /* if a default printer is found, validate the page */
    PrintService[] services = PrinterJob.lookupPrintServices();
    if (services.length != 0) {
        // no printers found on the system.                     
        format = PrinterJob.getPrinterJob().validatePage(format);
    }
    return format;
}
Also used : Locale(java.util.Locale) PageFormat(java.awt.print.PageFormat) MediaSize(javax.print.attribute.standard.MediaSize) Paper(java.awt.print.Paper) PrintService(javax.print.PrintService)

Aggregations

Paper (java.awt.print.Paper)18 PageFormat (java.awt.print.PageFormat)12 MediaSize (javax.print.attribute.standard.MediaSize)6 Media (javax.print.attribute.standard.Media)5 PrintService (javax.print.PrintService)4 MediaSizeName (javax.print.attribute.standard.MediaSizeName)4 OrientationRequested (javax.print.attribute.standard.OrientationRequested)4 Graphics2D (java.awt.Graphics2D)3 Rectangle (java.awt.Rectangle)3 PrinterException (java.awt.print.PrinterException)3 MediaPrintableArea (javax.print.attribute.standard.MediaPrintableArea)3 Font (java.awt.Font)2 FontMetrics (java.awt.FontMetrics)2 HeadlessException (java.awt.HeadlessException)2 Printable (java.awt.print.Printable)2 PrinterAbortException (java.awt.print.PrinterAbortException)2 PrinterJob (java.awt.print.PrinterJob)2 IOException (java.io.IOException)2 Calendar (java.util.Calendar)2 Preferences (java.util.prefs.Preferences)2