Java 8 PageFormat - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Java 8 PageFormat class.

This code example shows how to use the following methods:getHeight, getImageableHeight, getImageableWidth, getImageableX, getImageableY
        System.exit( 0 );
    } 
 
    public static void dumpPage(PageFormat pageFormat) {
        System.out.println(
            "page area: w=" + pageFormat.getWidth()
            + ", h=" + pageFormat.getHeight()
            + ", orientation=" 
            + (pageFormat.getOrientation() == PageFormat.LANDSCAPE ? "landscape" : "portrait")
        ); 
 
        System.out.println(
            "imageable area: x=" + pageFormat.getImageableX()
            + ", y=" + pageFormat.getImageableY()
            + ", w=" + pageFormat.getImageableWidth()
            + ", h=" + pageFormat.getImageableHeight()
        ); 
    } 
 
} 
/* vim:set et sw=4 ts=4: */ 
7
CodeRank
This code example shows how to use the following methods:getImageableHeight, getImageableWidth, getImageableX, getImageableY
        return bounds.getHeight();
    } 
 
    private void setPrintBounds(PageFormat format) {
        bounds = new Rectangle2D.Double(
            format.getImageableX(),
            format.getImageableY(),
            format.getImageableWidth(),
            format.getImageableHeight()
        ); 
    } 
} 
/* vim:set et sw=4 ts=4: */ 
7
CodeRank
This code example shows how to use the following methods:getHeight, getImageableHeight, getImageableWidth, getImageableX, getImageableY
    public void cancelPrint() { 
 
    } 
 
    public static void dumpPage(PageFormat pageFormat) {
        System.out.println("page area w:" + pageFormat.getWidth() + ", h: " + pageFormat.getHeight() + ", o: " + pageFormat.getOrientation());
 
        System.out.println("imageable area x: " +
                           pageFormat.getImageableX() + ", y: " + pageFormat.getImageableY() + ", w: " +
                           pageFormat.getImageableWidth() + ", h: " + pageFormat.getImageableHeight());
 
        Paper paper = pageFormat.getPaper();
 
        System.out.println("paper area w:" + paper.getWidth() + ", h: " + paper.getHeight());
        System.out.println("imageable area x: " +
                           paper.getImageableX() + ", y: " + paper.getImageableY() + ", w: " +
                           paper.getImageableWidth() + ", h: " + paper.getImageableHeight());
    } 
} 
7
CodeRank
This code example shows how to use the following methods:getHeight, getImageableHeight, getImageableWidth, getImageableX, getImageableY
 
  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();
  } 
 
  public int getOrientation() 
  { 
    return orientation;
  } 
6
CodeRank
This code example shows how to use the following methods:getImageableHeight, getImageableWidth, getImageableX, getImageableY
		/* 
		 * User (0,0) is typically outside the imageable area, so we must 
		 * translate by the X and Y values in the PageFormat to avoid clipping 
		 */ 
		Graphics2D g2d = (Graphics2D) g;
		g2d.translate(pf.getImageableX(), pf.getImageableY());
		double scale = getScaleToFit(pf);
		if (scale != 1.0) {
			g2d.scale(scale, scale);
		} 
		double imageHeight = pf.getImageableHeight() / scale;
		double clip = page * imageHeight;
		if (size.height > clip) {
			g2d.translate(0, -clip);
			g2d.setClip(0, (int) clip, (int) (pf.getImageableWidth() / scale),
					(int) imageHeight);
		} else { 
			return NO_SUCH_PAGE;
		} 
 

6
CodeRank
This code example shows how to use the following methods:getHeight, getImageableHeight, getImageableWidth, getImageableX, getImageableY
  private PageFormat[][] pageMapping;
 
  public DefaultPageGrid(final PageDefinition pageDefinition)
  { 
    final Rectangle2D[] pagePositions = pageDefinition.getPagePositions();
 
    final TreeSet horizontalPositions = new TreeSet();
    final TreeSet verticalPositions = new TreeSet();
 
    final int pagePosCount = pagePositions.length;
    for (int i = 0; i < pagePosCount; i++)
    { 
      final Rectangle2D pagePosition = pagePositions[i];
 
      final double minX = pagePosition.getMinX();
      final double maxX = pagePosition.getMaxX();
      final double minY = pagePosition.getMinY();
      final double maxY = pagePosition.getMaxY();
 
      if (minX == maxX || maxY == minY)
6
CodeRank
This code example shows how to use the following methods:setOrientation, setPaper
6
CodeRank
This code example shows how to use the following methods:getHeight, getImageableHeight, getImageableWidth, getImageableX, getImageableY
  } 
 
  public Insets getPageMargins(final PageFormat format)
  { 
 
    final int marginLeft = (int) format.getImageableX();
    final int marginRight = (int)
        (format.getWidth() - format.getImageableWidth() - format.getImageableX());
    final int marginTop = (int) (format.getImageableY());
    final int marginBottom = (int)
        (format.getHeight() - format.getImageableHeight() - format.getImageableY());
    return new Insets(marginTop, marginLeft, marginBottom, marginRight);
  } 
 
  public String getPageFormatName(final double width, final double height)
  { 
    try 
    { 
      final Field[] fields = PageSize.class.getFields();
      for (int i = 0; i < fields.length; i++)
6
CodeRank
This code example shows how to use the following methods:getImageableHeight, getImageableWidth, getImageableX, getImageableY
d = this.getPreferredSize();
      panelWidth  = d.width;    
      panelHeight = d.height;  
    } 
    double pageHeight = pf.getImageableHeight();   //height of printer page
    double pageWidth  = pf.getImageableWidth();    //width of printer page
    double scale = pageWidth/panelWidth;
    int totalNumPages = (int)Math.ceil(scale * panelHeight / pageHeight);
    // Make sure not print empty pages 
    if(pageIndex >= totalNumPages)
     return Printable.NO_SUCH_PAGE;
 
    // Shift Graphic to line up with beginning of print-imageable region 
    g2.translate(pf.getImageableX(), pf.getImageableY());
    // Shift Graphic to line up with beginning of next page to print 
    g2.translate(0f, -pageIndex*pageHeight);
    // Scale the page so the width fits... 
    g2.scale(scale, scale);
    paintComponent(g2);
6
CodeRank
This code example shows how to use the following methods:getHeight, getImageableHeight, getImageableWidth, getImageableX, getImageableY
    public double getZoom() { 
        if (zoomToPage || zoom < 0.01) {
            // actually this is zoom-to-page  
            Dimension dim = getParent().getSize();
            int resolution = Toolkit.getDefaultToolkit().getScreenResolution();
            double widthZoom = 72.0 * dim.getWidth() / resolution / format.getWidth();
            double heightZoom = 72.0 * dim.getHeight() / resolution / format.getHeight();
            return Math.min(widthZoom, heightZoom);
        } 
        return zoom;
    } 
         
    /** 
     * Get the current dimension of the page preview 
     *  
     * @return dimension in pixels 
     */ 
    public Dimension getZoomedPageDimension() {
        int resolution = Toolkit.getDefaultToolkit().getScreenResolution();
        double zoom = getZoom();

6
CodeRank
See Code Examples for Java 8 PageFormat Methods: