java.awt.print.PageFormat#setPaper ( )源码实例Demo

下面列出了java.awt.print.PageFormat#setPaper ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: dragonwell8_jdk   文件: WrongPaperPrintingTest.java
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPrintable(new WrongPaperPrintingTest(), job.validatePage(pf));
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
源代码2 项目: netbeans   文件: PrintPreferences.java
/**
 * 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;
}
 
private static void doTest() {
    PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
    aset.add(Chromaticity.MONOCHROME);

    MediaSize isoA5Size = MediaSize.getMediaSizeForName(MediaSizeName.ISO_A5);
    float[] size = isoA5Size.getSize(Size2DSyntax.INCH);
    Paper paper = new Paper();
    paper.setSize(size[0] * 72.0, size[1] * 72.0);
    paper.setImageableArea(0.0, 0.0, size[0] * 72.0, size[1] * 72.0);
    PageFormat pf = new PageFormat();
    pf.setPaper(paper);

    Book pageable = new Book();
    pageable.append(new WrongPaperForBookPrintingTest(), pf);

    PrinterJob job = PrinterJob.getPrinterJob();
    job.setPageable(pageable);
    if (job.printDialog()) {
        try {
            job.print(aset);
        } catch (PrinterException pe) {
            throw new RuntimeException(pe);
        }
    }
}
 
源代码4 项目: openjdk-jdk9   文件: PSPrinterJob.java
public EPSPrinter(Printable printable, String title,
                  PrintStream stream,
                  int x, int y, int wid, int hgt) {

    this.printable = printable;
    this.epsTitle = title;
    this.stream = stream;
    llx = x;
    lly = y;
    urx = llx+wid;
    ury = lly+hgt;
    // construct a PageFormat with zero margins representing the
    // exact bounds of the applet. ie construct a theoretical
    // paper which happens to exactly match applet panel size.
    Paper p = new Paper();
    p.setSize((double)wid, (double)hgt);
    p.setImageableArea(0.0,0.0, (double)wid, (double)hgt);
    pf = new PageFormat();
    pf.setPaper(p);
}
 
源代码5 项目: openjdk-jdk8u-backup   文件: PSPrinterJob.java
public EPSPrinter(Printable printable, String title,
                  PrintStream stream,
                  int x, int y, int wid, int hgt) {

    this.printable = printable;
    this.epsTitle = title;
    this.stream = stream;
    llx = x;
    lly = y;
    urx = llx+wid;
    ury = lly+hgt;
    // construct a PageFormat with zero margins representing the
    // exact bounds of the applet. ie construct a theoretical
    // paper which happens to exactly match applet panel size.
    Paper p = new Paper();
    p.setSize((double)wid, (double)hgt);
    p.setImageableArea(0.0,0.0, (double)wid, (double)hgt);
    pf = new PageFormat();
    pf.setPaper(p);
}
 
源代码6 项目: pentaho-reporting   文件: PageReadHandler.java
/**
 * Handles the page format.
 *
 * @param atts
 *          the attributes.
 * @throws SAXException
 *           if a parser error occurs or the validation failed.
 * @noinspection SuspiciousNameCombination
 */
private void handlePageFormat( final Attributes atts ) throws SAXException {
  final MasterReport report =
      (MasterReport) getRootHandler().getHelperObject( ReportParserUtil.HELPER_OBJ_REPORT_NAME );

  // grab the default page definition ...
  PageFormat format = report.getPageDefinition().getPageFormat( 0 );
  float defTopMargin = (float) format.getImageableY();
  float defBottomMargin = (float) ( format.getHeight() - format.getImageableHeight() - format.getImageableY() );
  float defLeftMargin = (float) format.getImageableX();
  float defRightMargin = (float) ( format.getWidth() - format.getImageableWidth() - format.getImageableX() );

  format = createPageFormat( format, atts );

  defTopMargin = ParserUtil.parseFloat( atts.getValue( getUri(), PageReadHandler.TOPMARGIN_ATT ), defTopMargin );
  defBottomMargin =
      ParserUtil.parseFloat( atts.getValue( getUri(), PageReadHandler.BOTTOMMARGIN_ATT ), defBottomMargin );
  defLeftMargin = ParserUtil.parseFloat( atts.getValue( getUri(), PageReadHandler.LEFTMARGIN_ATT ), defLeftMargin );
  defRightMargin = ParserUtil.parseFloat( atts.getValue( getUri(), PageReadHandler.RIGHTMARGIN_ATT ), defRightMargin );

  final Paper p = format.getPaper();
  switch ( format.getOrientation() ) {
    case PageFormat.PORTRAIT:
      PageFormatFactory.getInstance().setBorders( p, defTopMargin, defLeftMargin, defBottomMargin, defRightMargin );
      break;
    case PageFormat.LANDSCAPE:
      // right, top, left, bottom
      PageFormatFactory.getInstance().setBorders( p, defRightMargin, defTopMargin, defLeftMargin, defBottomMargin );
      break;
    case PageFormat.REVERSE_LANDSCAPE:
      PageFormatFactory.getInstance().setBorders( p, defLeftMargin, defBottomMargin, defRightMargin, defTopMargin );
      break;
    default:
      // will not happen..
      throw new IllegalArgumentException( "Unexpected paper orientation." );
  }

  format.setPaper( p );
  pageFormat = format;
}
 
源代码7 项目: pentaho-reporting   文件: PageFormatSerializer.java
/**
 * Restores a page format after it has been serialized.
 *
 * @param data the serialized page format data.
 * @return the restored page format.
 */
private PageFormat createPageFormat( final Object[] data ) {
  final Integer orientation = (Integer) data[ 0 ];
  final float[] dim = (float[]) data[ 1 ];
  final float[] rect = (float[]) data[ 2 ];
  final Paper p = new Paper();
  p.setSize( dim[ 0 ], dim[ 1 ] );
  p.setImageableArea( rect[ 0 ], rect[ 1 ], rect[ 2 ], rect[ 3 ] );
  final PageFormat format = new PageFormat();
  format.setPaper( p );
  format.setOrientation( orientation.intValue() );
  return format;
}
 
源代码8 项目: openjdk-jdk9   文件: RasterPrinterJob.java
/**
 * 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;
}
 
源代码9 项目: jdk8u-dev-jdk   文件: RasterPrinterJob.java
/**
 * 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;
}
 
/**
 * Handles the page format.
 *
 * @param atts
 *          the attributes.
 * @throws SAXException
 *           if a parser error occurs or the validation failed.
 * @noinspection SuspiciousNameCombination
 */
private PageFormat configurePageSizeAndMargins( final Attributes atts, PageFormat format ) throws SAXException {
  // (1) Grab the existing default ...
  float defTopMargin = (float) format.getImageableY();
  float defBottomMargin = (float) ( format.getHeight() - format.getImageableHeight() - format.getImageableY() );
  float defLeftMargin = (float) format.getImageableX();
  float defRightMargin = (float) ( format.getWidth() - format.getImageableWidth() - format.getImageableX() );

  // (2) Now configure the new paper-size
  format = configurePageSize( format, atts );

  // (3) Reconfigure margins as requested
  defTopMargin = ParserUtil.parseFloat( atts.getValue( getUri(), "margin-top" ), defTopMargin );
  defBottomMargin = ParserUtil.parseFloat( atts.getValue( getUri(), "margin-bottom" ), defBottomMargin );
  defLeftMargin = ParserUtil.parseFloat( atts.getValue( getUri(), "margin-left" ), defLeftMargin );
  defRightMargin = ParserUtil.parseFloat( atts.getValue( getUri(), "margin-right" ), defRightMargin );

  final Paper p = format.getPaper();
  switch ( format.getOrientation() ) {
    case PageFormat.PORTRAIT:
      PageFormatFactory.getInstance().setBorders( p, defTopMargin, defLeftMargin, defBottomMargin, defRightMargin );
      break;
    case PageFormat.REVERSE_LANDSCAPE:
      PageFormatFactory.getInstance().setBorders( p, defLeftMargin, defBottomMargin, defRightMargin, defTopMargin );
      break;
    case PageFormat.LANDSCAPE:
      PageFormatFactory.getInstance().setBorders( p, defRightMargin, defTopMargin, defLeftMargin, defBottomMargin );
      break;
    default:
      // will not happen..
      throw new IllegalArgumentException( "Unexpected paper orientation." );
  }

  format.setPaper( p );
  return format;
}
 
源代码11 项目: Bytecoder   文件: RasterPrinterJob.java
/**
 * 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;
}
 
源代码12 项目: jdk8u_jdk   文件: RasterPrinterJob.java
/**
 * 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 (!Locale.getDefault().equals(Locale.ENGLISH) && // ie "C"
        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;
}
 
源代码13 项目: dragonwell8_jdk   文件: PrintJob2D.java
public boolean printDialog() {

        boolean proceedWithPrint = false;

        printerJob = PrinterJob.getPrinterJob();
        if (printerJob == null) {
            return false;
        }
        DialogType d = this.jobAttributes.getDialog();
        PrintService pServ = printerJob.getPrintService();
        if ((pServ == null) &&  (d == DialogType.NONE)){
            return false;
        }
        copyAttributes(pServ);

        DefaultSelectionType select =
            this.jobAttributes.getDefaultSelection();
        if (select == DefaultSelectionType.RANGE) {
            attributes.add(SunPageSelection.RANGE);
        } else if (select == DefaultSelectionType.SELECTION) {
            attributes.add(SunPageSelection.SELECTION);
        } else {
            attributes.add(SunPageSelection.ALL);
        }

        if (frame != null) {
             attributes.add(new DialogOwner(frame));
         }

        if ( d == DialogType.NONE) {
            proceedWithPrint = true;
        } else {
            if (d == DialogType.NATIVE) {
                attributes.add(DialogTypeSelection.NATIVE);
            }  else { //  (d == DialogType.COMMON)
                attributes.add(DialogTypeSelection.COMMON);
            }
            if (proceedWithPrint = printerJob.printDialog(attributes)) {
                if (pServ == null) {
                    // Windows gives an option to install a service
                    // when it detects there are no printers so
                    // we make sure we get the updated print service.
                    pServ = printerJob.getPrintService();
                    if (pServ == null) {
                        return false;
                    }
                }
                updateAttributes();
                translateOutputProps();
            }
        }

        if (proceedWithPrint) {

            JobName jname = (JobName)attributes.get(JobName.class);
            if (jname != null) {
                printerJob.setJobName(jname.toString());
            }

            pageFormat = new PageFormat();

            Media media = (Media)attributes.get(Media.class);
            MediaSize mediaSize =  null;
            if (media != null  && media instanceof MediaSizeName) {
                mediaSize = MediaSize.getMediaSizeForName((MediaSizeName)media);
            }

            Paper p = pageFormat.getPaper();
            if (mediaSize != null) {
                p.setSize(mediaSize.getX(MediaSize.INCH)*72.0,
                          mediaSize.getY(MediaSize.INCH)*72.0);
            }

            if (pageAttributes.getOrigin()==OriginType.PRINTABLE) {
                // AWT uses 1/4" borders by default
                p.setImageableArea(18.0, 18.0,
                                   p.getWidth()-36.0,
                                   p.getHeight()-36.0);
            } else {
                p.setImageableArea(0.0,0.0,p.getWidth(),p.getHeight());
            }

            pageFormat.setPaper(p);

            OrientationRequested orient =
               (OrientationRequested)attributes.get(OrientationRequested.class);
            if (orient!= null &&
                orient == OrientationRequested.REVERSE_LANDSCAPE) {
                pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);
            } else if (orient == OrientationRequested.LANDSCAPE) {
                pageFormat.setOrientation(PageFormat.LANDSCAPE);
            } else {
                pageFormat.setOrientation(PageFormat.PORTRAIT);
                }

            printerJob.setPrintable(this, pageFormat);

        }

        return proceedWithPrint;
    }
 
源代码14 项目: hottub   文件: RasterPrinterJob.java
/**
 * 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 (!Locale.getDefault().equals(Locale.ENGLISH) && // ie "C"
        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;
}
 
源代码15 项目: openjdk-8   文件: RasterPrinterJob.java
/**
 * 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 (!Locale.getDefault().equals(Locale.ENGLISH) && // ie "C"
        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;
}
 
源代码16 项目: jdk8u-jdk   文件: PrintJob2D.java
public boolean printDialog() {

        boolean proceedWithPrint = false;

        printerJob = PrinterJob.getPrinterJob();
        if (printerJob == null) {
            return false;
        }
        DialogType d = this.jobAttributes.getDialog();
        PrintService pServ = printerJob.getPrintService();
        if ((pServ == null) &&  (d == DialogType.NONE)){
            return false;
        }
        copyAttributes(pServ);

        DefaultSelectionType select =
            this.jobAttributes.getDefaultSelection();
        if (select == DefaultSelectionType.RANGE) {
            attributes.add(SunPageSelection.RANGE);
        } else if (select == DefaultSelectionType.SELECTION) {
            attributes.add(SunPageSelection.SELECTION);
        } else {
            attributes.add(SunPageSelection.ALL);
        }

        if (frame != null) {
             attributes.add(new DialogOwner(frame));
         }

        if ( d == DialogType.NONE) {
            proceedWithPrint = true;
        } else {
            if (d == DialogType.NATIVE) {
                attributes.add(DialogTypeSelection.NATIVE);
            }  else { //  (d == DialogType.COMMON)
                attributes.add(DialogTypeSelection.COMMON);
            }
            if (proceedWithPrint = printerJob.printDialog(attributes)) {
                if (pServ == null) {
                    // Windows gives an option to install a service
                    // when it detects there are no printers so
                    // we make sure we get the updated print service.
                    pServ = printerJob.getPrintService();
                    if (pServ == null) {
                        return false;
                    }
                }
                updateAttributes();
                translateOutputProps();
            }
        }

        if (proceedWithPrint) {

            JobName jname = (JobName)attributes.get(JobName.class);
            if (jname != null) {
                printerJob.setJobName(jname.toString());
            }

            pageFormat = new PageFormat();

            Media media = (Media)attributes.get(Media.class);
            MediaSize mediaSize =  null;
            if (media != null  && media instanceof MediaSizeName) {
                mediaSize = MediaSize.getMediaSizeForName((MediaSizeName)media);
            }

            Paper p = pageFormat.getPaper();
            if (mediaSize != null) {
                p.setSize(mediaSize.getX(MediaSize.INCH)*72.0,
                          mediaSize.getY(MediaSize.INCH)*72.0);
            }

            if (pageAttributes.getOrigin()==OriginType.PRINTABLE) {
                // AWT uses 1/4" borders by default
                p.setImageableArea(18.0, 18.0,
                                   p.getWidth()-36.0,
                                   p.getHeight()-36.0);
            } else {
                p.setImageableArea(0.0,0.0,p.getWidth(),p.getHeight());
            }

            pageFormat.setPaper(p);

            OrientationRequested orient =
               (OrientationRequested)attributes.get(OrientationRequested.class);
            if (orient!= null &&
                orient == OrientationRequested.REVERSE_LANDSCAPE) {
                pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);
            } else if (orient == OrientationRequested.LANDSCAPE) {
                pageFormat.setOrientation(PageFormat.LANDSCAPE);
            } else {
                pageFormat.setOrientation(PageFormat.PORTRAIT);
                }

            printerJob.setPrintable(this, pageFormat);

        }

        return proceedWithPrint;
    }
 
源代码17 项目: ramus   文件: Options.java
public static PageFormat getPageFormat(String name, PageFormat pageFormat) {
    Properties properties = getProperties(name);
    if (properties == null)
        return pageFormat;
    final String orientation = properties.getProperty(ORIENTATION);
    if (LANDSCAPE.equals(orientation))
        pageFormat.setOrientation(PageFormat.LANDSCAPE);
    else if (PORTRAIT.equals(orientation))
        pageFormat.setOrientation(PageFormat.PORTRAIT);
    else if (REVERSE_LANDSCAPE.equals(orientation))
        pageFormat.setOrientation(PageFormat.REVERSE_LANDSCAPE);

    String s = properties.getProperty(PAPER_IMAGEABLE_HEIGHT);
    if (s == null)
        return pageFormat;
    double iHeight = Double.parseDouble(s);
    s = properties.getProperty(PAPER_IMAGEABLE_WIDTH);
    if (s == null)
        return pageFormat;
    double iWidth = Double.parseDouble(s);

    s = properties.getProperty(PAPER_HEIGHT);
    if (s == null)
        return pageFormat;
    double height = Double.parseDouble(s);
    s = properties.getProperty(PAPER_WIDTH);
    if (s == null)
        return pageFormat;
    double width = Double.parseDouble(s);

    s = properties.getProperty(PAPER_IMAGEABLE_X);
    if (s == null)
        return pageFormat;
    final double x = Double.parseDouble(s);
    s = properties.getProperty(PAPER_IMAGEABLE_Y);
    if (s == null)
        return pageFormat;
    final double y = Double.parseDouble(s);
    final Paper paper = pageFormat.getPaper();
    paper.setImageableArea(x, y, iWidth, iHeight);
    paper.setSize(width, height);
    pageFormat.setPaper(paper);
    return pageFormat;
}
 
源代码18 项目: tn5250j   文件: PrinterAttributesPanel.java
private void getLandscapeAttributes() {

    PrinterJob printJob = PrinterJob.getPrinterJob();

    PageFormat documentPageFormat = new PageFormat();
    documentPageFormat.setOrientation(PageFormat.LANDSCAPE);
    documentPageFormat.setPaper(pappyLand);

    documentPageFormat = printJob.pageDialog(documentPageFormat);

    pappyLand = documentPageFormat.getPaper();


  }
 
源代码19 项目: pentaho-reporting   文件: PageFormatFactory.java
/**
 * Creates a new pageformat using the given paper and the given orientation.
 *
 * @param paper
 *          the paper to use in the new pageformat
 * @param orientation
 *          one of PageFormat.PORTRAIT, PageFormat.LANDSCAPE or PageFormat.REVERSE_LANDSCAPE
 * @return the created Pageformat
 * @throws NullPointerException
 *           if the paper given was null
 */
public PageFormat createPageFormat( final Paper paper, final int orientation ) {
  if ( paper == null ) {
    throw new NullPointerException( "Paper given must not be null" );
  }
  final PageFormat pf = new PageFormat();
  pf.setPaper( paper );
  pf.setOrientation( orientation );
  return pf;
}
 
源代码20 项目: haxademic   文件: PrintPageDirectNew.java
public void sendToDefaultPrinter() {
	// configure the printing job & simple single-page document
	PrinterJob printJob = PrinterJob.getPrinterJob();
	
	
	
	PageFormat pageFormat = printJob.defaultPage();
	Paper paper = pageFormat.getPaper();
	
	float inchWidth = 16;
	float inchHeight = 20;
	
	float marginWidth = 100;
	float marginHeight = 100;
	
	int pWidth = (int) ((inchWidth * 25.4f) * 2.835f);// quick: convert inch to mm, mm to pt
	int pHeight = (int) ((inchHeight * 25.4f) * 2.835f);
	
	paper.setSize(pWidth, pHeight);
	paper.setImageableArea(marginWidth, marginHeight, pWidth, pHeight);
	pageFormat.setPaper(paper);
	
	//not sure this exactly works, we should probably just scale the square to fit and we send it the correct rotation orientation
	//pageFormat.setOrientation(PageFormat.LANDSCAPE);
	

	// we might also be able to set attributes here
	Printable page = new ImagePage();
	Book book = new Book();
	
	book.append(page, pageFormat);
	
	
	/*
	Early testing at "LikeMinded Productions":
	
	PageFormat documentPageFormat = new PageFormat();
	
	// new settings to play with
	Paper pape = new Paper();
	pape.setSize(10000, 6000);
	pape.setImageableArea(0, 0, 10000, 6000);
	documentPageFormat.setPaper(pape);
	
	documentPageFormat.setOrientation(PageFormat.LANDSCAPE);
	*/
	
	
	printJob.setPageable(book);

	// use the print dialog UI or just print it!
	if(useDialog) {
		if (printJob.printDialog()) printPage(printJob);
	} else {
		printPage(printJob);
	}
}