There are 4 code examples for java.awt.print.PageFormat.

The API names are highlighted below. You can use suckoo button to vote the code example(s) you like. The best code example will be ranked first next time. Thanks a lot for your feedback.

Project Name: druid Package: org.dlib.gui.print

Source Code: GraphicPrinter.java (Click to view .java file)

Method Code:
vote
like

private PageFormat getPageFormat(){
  MediaSizeName media=(MediaSizeName)attr.get(Media.class);
  MediaSize mediaSize=MediaSize.getMediaSizeForName(media);
  MediaPrintableArea area=(MediaPrintableArea)attr.get(MediaPrintableArea.class);
  double width=MM2PIXEL * mediaSize.getX(MediaSize.MM);
  double height=MM2PIXEL * mediaSize.getY(MediaSize.MM);
  double imgX=MM2PIXEL * area.getX(MediaPrintableArea.MM);
  double imgY=MM2PIXEL * area.getY(MediaPrintableArea.MM);
  double imgW=MM2PIXEL * area.getWidth(MediaPrintableArea.MM);
  double imgH=MM2PIXEL * area.getHeight(MediaPrintableArea.MM);
  Paper paper=new Paper();
  paper.setSize(width,height);
  paper.setImageableArea(imgX,imgY,imgW,imgH);
  PageFormat pf=new PageFormat();
  pf.setPaper(paper);
  return pf;
}
 

Project Name: jFreeChart Package: org.jfree.chart

Source Code: ChartPanel.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Prints the chart on a single page.
 * @param g  the graphics context.
 * @param pf  the page format to use.
 * @param pageIndex  the index of the page. If not <code>0</code>, nothing
 * gets print.
 * @return The result of printing.
 */
public int print(Graphics g,PageFormat pf,int pageIndex){
  if (pageIndex != 0) {
    return NO_SUCH_PAGE;
  }
  Graphics2D g2=(Graphics2D)g;
  double x=pf.getImageableX();
  double y=pf.getImageableY();
  double w=pf.getImageableWidth();
  double h=pf.getImageableHeight();
  this.chart.draw(g2,new Rectangle2D.Double(x,y,w,h),this.anchor,null);
  return PAGE_EXISTS;
}
 

Project Name: weka Package: weka.classifiers.bayes.net

Source Code: GUI.java (Click to view .java file)

Method Code:
vote
like

/** 
 * implementation of Printable, used for printing
 * @see Printable
 */
public int print(Graphics g,PageFormat pageFormat,int pageIndex){
  if (pageIndex > 0) {
    return (NO_SUCH_PAGE);
  }
 else {
    Graphics2D g2d=(Graphics2D)g;
    g2d.translate(pageFormat.getImageableX(),pageFormat.getImageableY());
    double fHeight=pageFormat.getImageableHeight();
    double fWidth=pageFormat.getImageableWidth();
    int xMax=1;
    int yMax=1;
    for (int iNode=0; iNode < m_BayesNet.getNrOfNodes(); iNode++) {
      if (xMax < m_BayesNet.getPositionX(iNode)) {
        xMax=m_BayesNet.getPositionX(iNode);
      }
      if (yMax < m_BayesNet.getPositionY(iNode)) {
        yMax=m_BayesNet.getPositionY(iNode);
      }
    }
    double fCurrentScale=m_fScale;
    xMax+=m_nPaddedNodeWidth + 100;
    if (fWidth / xMax < fHeight / yMax) {
      m_fScale=fWidth / xMax;
    }
 else {
      m_fScale=fHeight / yMax;
    }
    paint(g2d);
    m_fScale=fCurrentScale;
    return (PAGE_EXISTS);
  }
}
 

Project Name: weka Package: weka.gui

Source Code: DocumentPrinting.java (Click to view .java file)

Method Code:
vote
like

/** 
 * Shows the print dialog.
 */
public void printDialog(){
  if (m_PrinterJob.printDialog()) {
    m_PrinterJob.setPrintable(this,m_PageFormat);
    try {
      m_PrinterJob.print();
    }
 catch (    PrinterException printerException) {
      m_PageStartY=0;
      m_PageEndY=0;
      m_CurrentPage=-1;
      System.out.println("Error Printing Document");
    }
  }
}