类java.awt.print.Paper源码实例Demo

下面列出了怎么用java.awt.print.Paper的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: jdk8u-jdk   文件: 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);
}
 
源代码2 项目: gcs   文件: PrintManager.java
/** @return A newly created {@link PageFormat} with the current settings. */
public PageFormat createPageFormat() {
    PageFormat      format      = new PageFormat();
    PageOrientation orientation = getPageOrientation();
    double[]        size        = getPaperSize(LengthUnits.PT);
    double[]        margins     = getPaperMargins(LengthUnits.PT);
    Paper           paper       = new Paper();

    if (orientation == PageOrientation.PORTRAIT) {
        format.setOrientation(PageFormat.PORTRAIT);
    } else if (orientation == PageOrientation.LANDSCAPE) {
        format.setOrientation(PageFormat.LANDSCAPE);
    } else if (orientation == PageOrientation.REVERSE_PORTRAIT) {
        // REVERSE_PORTRAIT doesn't exist in the old PageFormat class
        format.setOrientation(PageFormat.PORTRAIT);
    } else if (orientation == PageOrientation.REVERSE_LANDSCAPE) {
        format.setOrientation(PageFormat.REVERSE_LANDSCAPE);
    }
    paper.setSize(size[0], size[1]);
    paper.setImageableArea(margins[1], margins[0], size[0] - (margins[1] + margins[3]), size[1] - (margins[0] + margins[2]));
    format.setPaper(paper);
    return format;
}
 
源代码3 项目: jpexs-decompiler   文件: Test.java
public static void main(String[] args) throws Exception {
    PDFJob job=new PDFJob(new FileOutputStream("test.pdf"));   
    PageFormat pf=new PageFormat();
    pf.setOrientation(PageFormat.PORTRAIT);
    Paper p = new Paper();
    p.setSize(210,297); //A4
    pf.setPaper(p);
    
    BufferedImage img = ImageIO.read(new File("earth.jpg"));
    
    int w = 200;
    
    for(int i=0;i<10;i++){
        Graphics g = job.getGraphics();
        g.drawImage(img, 0, 0,w,w, null);
        g.dispose();
    }
    
    job.end();
}
 
源代码4 项目: pentaho-reporting   文件: TextFilePrinterDriver.java
/**
 * Resets the printer and starts a new page. Prints the top border lines (if necessary).
 *
 * @throws java.io.IOException
 *           if there was an IOError while writing the command
 */
public void startPage( final Paper paper, final String encoding ) throws IOException {
  this.defaultEncoding = encoding;

  if ( firstPage ) {
    final EncodingUtilities encodingUtilities = getEncodingUtilities( encoding );
    out.write( encodingUtilities.getEncodingHeader() );
    firstPage = false;
  }

  final PageFormatFactory fact = PageFormatFactory.getInstance();
  final float charWidthPoints = 72.0f / getCharactersPerInch();
  borderLeft = (int) ( fact.getLeftBorder( paper ) / charWidthPoints );

  final float lineHeightPoints = 72.0f / getLinesPerInch();
  final int borderTop = (int) ( fact.getTopBorder( paper ) / lineHeightPoints );

  for ( int i = 0; i < borderTop; i++ ) {
    startLine();
    endLine( false );
  }
}
 
源代码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);
}
 
/**
 * Creates a report format by calling API methods directly.
 *
 * @return A report.
 */
public MasterReport createReport()
{

  final MasterReport report = new MasterReport();
  report.setName("Survey Scale Demo Report");

  // use A4...
  final PageFormatFactory pff = PageFormatFactory.getInstance();
  final Paper paper = pff.createPaper(PageSize.A4);
  pff.setBorders(paper, PAGE_MARGIN_TOP, PAGE_MARGIN_LEFT, PAGE_MARGIN_BOTTOM, PAGE_MARGIN_RIGHT);
  final PageFormat format = pff.createPageFormat(paper, PageFormat.PORTRAIT);
  report.setPageDefinition(new SimplePageDefinition(format));

  setupWatermark(report);
  setupPageHeader(report);
  //// REPORT GROUP /////////////////////////////////////////////////////////////////////////
  setupGroup(report);
  //// ITEM BAND ////////////////////////////////////////////////////////////////////////////
  setupItemBand(report);
  //// PAGE FOOTER //////////////////////////////////////////////////////////////////////////
  setupPageFooter(report);

  report.getParameterValues().put("RESPONDENT_NAME", "Dave");
  report.setDataFactory(new TableDataFactory
      ("default", data));
  return report;
}
 
源代码7 项目: netbeans   文件: PrintPreferencesTest.java
public void testGetPageFormat() {
    PrinterJob pj = PrinterJob.getPrinterJob();
    PageFormat expResult = PrintPreferences.getPageFormat(pj);
    PrintPreferences.setPageFormat(expResult);
    PageFormat result = PrintPreferences.getPageFormat(pj);
    assertEquals(expResult.getHeight(), result.getHeight());
    assertEquals(expResult.getWidth(), result.getWidth());
    assertEquals(expResult.getOrientation(), result.getOrientation());
    assertEquals(expResult.getPaper().getHeight(), result.getPaper().getHeight());
    assertEquals(expResult.getPaper().getWidth(), result.getPaper().getWidth());
    assertEquals(expResult.getPaper().getImageableHeight(), result.getPaper().getImageableHeight());
    assertEquals(expResult.getPaper().getImageableWidth(), result.getPaper().getImageableWidth());
    assertEquals(expResult.getPaper().getImageableX(), result.getPaper().getImageableX());
    assertEquals(expResult.getPaper().getImageableY(), result.getPaper().getImageableY());
    
    double w = expResult.getPaper().getWidth() + 10;
    double h = expResult.getPaper().getHeight() + 10;
    Paper p = expResult.getPaper();
    double ix = p.getImageableX() + 10;
    double iy = p.getImageableY() + 10;
    double iw = p.getImageableWidth() + 10;
    double ih = p.getImageableHeight() + 10;
    p.setImageableArea(ix, iy, iw, ih);
    p.setSize(w, h);
    expResult.setPaper(p);
    PrintPreferences.setPageFormat(expResult);
    assertEquals(h, PrintPreferences.getPageFormat(pj).getHeight());
    assertEquals(w, PrintPreferences.getPageFormat(pj).getWidth());
    assertEquals(ix, PrintPreferences.getPageFormat(pj).getPaper().getImageableX());
    assertEquals(iy, PrintPreferences.getPageFormat(pj).getPaper().getImageableY());
    assertEquals(iw, PrintPreferences.getPageFormat(pj).getPaper().getImageableWidth());
    assertEquals(ih, PrintPreferences.getPageFormat(pj).getPaper().getImageableHeight());
    
    expResult.setOrientation(PageFormat.REVERSE_LANDSCAPE);
    PrintPreferences.setPageFormat(expResult);
    assertEquals(PageFormat.REVERSE_LANDSCAPE, PrintPreferences.getPageFormat(pj).getOrientation());
}
 
源代码8 项目: pentaho-reporting   文件: PlainTextPage.java
/**
 * Creates a new PlainTextPage with the given dimensions and the specified PrinterCommandSet.
 *
 * @param driver
 *          the command-set for printing and formatting the text.
 */
public PlainTextPage( final Paper pageFormat, final PrinterDriver driver, final String defaultEncoding ) {
  if ( driver == null ) {
    throw new NullPointerException( "PrinterCommandSet must be defined." );
  }
  if ( pageFormat == null ) {
    throw new NullPointerException( "PageFormat must be defined." );
  }
  if ( defaultEncoding == null ) {
    throw new NullPointerException( "DefaultEncoding must be defined." );
  }

  final float characterWidthInPoint = ( 72.0f / driver.getCharactersPerInch() );
  final float characterHeightInPoint = ( 72.0f / driver.getLinesPerInch() );

  final int currentPageHeight =
      PlainTextPage.correctedDivisionFloor( pageFormat.getImageableHeight(), characterHeightInPoint );
  final int currentPageWidth =
      PlainTextPage.correctedDivisionFloor( pageFormat.getImageableWidth(), characterWidthInPoint );

  // Log.debug("Created page with " + currentPageWidth + ", " + currentPageHeight);
  pageBuffer = new PlaintextDataChunk[currentPageWidth][currentPageHeight];
  width = currentPageWidth;
  height = currentPageHeight;
  paper = pageFormat;
  this.driver = driver;
  this.defaultEncoding = defaultEncoding;
}
 
源代码9 项目: jdk8u-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;
}
 
源代码10 项目: 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;
}
 
源代码11 项目: pentaho-reporting   文件: TextDocumentWriter.java
public void processPhysicalPage( final PageGrid pageGrid, final LogicalPageBox logicalPage, final int row,
    final int col, final PhysicalPageKey pageKey ) throws IOException {
  final PhysicalPageBox page = pageGrid.getPage( row, col );
  final Paper paper = new Paper();
  paper.setSize( StrictGeomUtility.toExternalValue( page.getWidth() ), StrictGeomUtility.toExternalValue( page
      .getHeight() ) );
  paper.setImageableArea( StrictGeomUtility.toExternalValue( page.getImageableX() ), StrictGeomUtility
      .toExternalValue( page.getImageableY() ), StrictGeomUtility.toExternalValue( page.getImageableWidth() ),
      StrictGeomUtility.toExternalValue( page.getImageableHeight() ) );
  drawArea = new StrictBounds( page.getGlobalX(), page.getGlobalY(), page.getWidth(), page.getHeight() );
  plainTextPage = new PlainTextPage( paper, driver, encoding );
  processPageBox( logicalPage );
  plainTextPage.writePage();
}
 
/**
 * 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;
}
 
/**
 * Resets the printer and starts a new page. Prints the top border lines (if necessary).
 *
 * @throws java.io.IOException
 *           if there was an IOError while writing the command
 */
public void startPage( final Paper paper, final String encoding ) throws IOException {
  this.encoding = encoding;
  final float charWidthPoints = 72.0f / getCharactersPerInch();
  final float lineHeightPoints = 72.0f / getLinesPerInch();

  if ( firstPage ) {
    // update the autoLF setting
    sendAutoLF( isAutoLF() );
    sendDefinePrintQuality( getPrintQuality() );
    sendDefineCharacterWidth( getCharactersPerInch() );
    firstPage = false;
  }

  // set the line spacing ..
  sendLineSpacing( (int) lineHeightPoints );

  // define the page size ..
  // we redefine it for every page, as we do not assume that the page sizes
  // will be the same for the whole report.
  final int lines = (int) ( ( paper.getHeight() / 72.0f ) * getLinesPerInch() );
  sendDefinePageLengthInLines( lines );

  final PageFormatFactory fact = PageFormatFactory.getInstance();
  final int borderLeft = (int) ( fact.getLeftBorder( paper ) / charWidthPoints );
  final int borderRight = (int) ( fact.getRightBorder( paper ) / charWidthPoints );

  final int borderTop = (int) ( fact.getTopBorder( paper ) / lineHeightPoints );
  sendDefineHorizontalBorders( borderLeft, borderRight );

  // print the top margin ..
  for ( int i = 0; i < borderTop; i++ ) {
    startLine();
    endLine( false );
  }

}
 
源代码14 项目: jdk8u60   文件: 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;
}
 
/**
 * Starts parsing.
 *
 * @param attrs the attributes.
 * @throws SAXException if there is a parsing error.
 */
protected void startParsing( final Attributes attrs ) throws SAXException {
  final Dimension2D pageSize = DoubleDimensionConverter.getObject( attrs.getValue( getUri(), "pageSize" ) );
  final double topBorder = Double.parseDouble( attrs.getValue( getUri(), "topBorder" ) );
  final double leftBorder = Double.parseDouble( attrs.getValue( getUri(), "leftBorder" ) );
  final double bottomBorder = Double.parseDouble( attrs.getValue( getUri(), "bottomBorder" ) );
  final double rightBorder = Double.parseDouble( attrs.getValue( getUri(), "rightBorder" ) );

  final Paper paper = PageFormatFactory.getInstance().createPaper( pageSize.getWidth(), pageSize.getHeight() );
  PageFormatFactory.getInstance().setBorders( paper, topBorder, leftBorder, bottomBorder, rightBorder );

  pageFormat = new PageFormat();
  pageFormat.setPaper( paper );

}
 
源代码16 项目: openjdk-8-source   文件: PSPrinterJob.java
protected double getPhysicalPrintableWidth(Paper p) {
    return p.getImageableWidth();
}
 
源代码17 项目: jdk8u_jdk   文件: RasterPrinterJob.java
/**
 * updates a Paper object to reflect the current printer's selected
 * paper size and imageable area for that paper size.
 * Default implementation copies settings from the original, applies
 * applies some validity checks, changes them only if they are
 * clearly unreasonable, then sets them into the new Paper.
 * Subclasses are expected to override this method to make more
 * informed decisons.
 */
protected void validatePaper(Paper origPaper, Paper newPaper) {
    if (origPaper == null || newPaper == null) {
        return;
    } else {
        double wid = origPaper.getWidth();
        double hgt = origPaper.getHeight();
        double ix = origPaper.getImageableX();
        double iy = origPaper.getImageableY();
        double iw = origPaper.getImageableWidth();
        double ih = origPaper.getImageableHeight();

        /* Assume any +ve values are legal. Overall paper dimensions
         * take precedence. Make sure imageable area fits on the paper.
         */
        Paper defaultPaper = new Paper();
        wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
        hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
        ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
        iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
        iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
        ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
        /* full width/height is not likely to be imageable, but since we
         * don't know the limits we have to allow it
         */
        if (iw > wid) {
            iw = wid;
        }
        if (ih > hgt) {
            ih = hgt;
        }
        if ((ix + iw) > wid) {
            ix = wid - iw;
        }
        if ((iy + ih) > hgt) {
            iy = hgt - ih;
        }
        newPaper.setSize(wid, hgt);
        newPaper.setImageableArea(ix, iy, iw, ih);
    }
}
 
源代码18 项目: jdk8u-dev-jdk   文件: WPrinterJob.java
@Override
protected double getPhysicalPrintableX(Paper p) {
    return mPrintPhysX;
}
 
源代码19 项目: jdk8u_jdk   文件: WPrinterJob.java
@Override
protected double getPhysicalPrintableX(Paper p) {
    return mPrintPhysX;
}
 
源代码20 项目: dragonwell8_jdk   文件: RasterPrinterJob.java
/**
 * updates a Paper object to reflect the current printer's selected
 * paper size and imageable area for that paper size.
 * Default implementation copies settings from the original, applies
 * applies some validity checks, changes them only if they are
 * clearly unreasonable, then sets them into the new Paper.
 * Subclasses are expected to override this method to make more
 * informed decisons.
 */
protected void validatePaper(Paper origPaper, Paper newPaper) {
    if (origPaper == null || newPaper == null) {
        return;
    } else {
        double wid = origPaper.getWidth();
        double hgt = origPaper.getHeight();
        double ix = origPaper.getImageableX();
        double iy = origPaper.getImageableY();
        double iw = origPaper.getImageableWidth();
        double ih = origPaper.getImageableHeight();

        /* Assume any +ve values are legal. Overall paper dimensions
         * take precedence. Make sure imageable area fits on the paper.
         */
        Paper defaultPaper = new Paper();
        wid = ((wid > 0.0) ? wid : defaultPaper.getWidth());
        hgt = ((hgt > 0.0) ? hgt : defaultPaper.getHeight());
        ix = ((ix > 0.0) ? ix : defaultPaper.getImageableX());
        iy = ((iy > 0.0) ? iy : defaultPaper.getImageableY());
        iw = ((iw > 0.0) ? iw : defaultPaper.getImageableWidth());
        ih = ((ih > 0.0) ? ih : defaultPaper.getImageableHeight());
        /* full width/height is not likely to be imageable, but since we
         * don't know the limits we have to allow it
         */
        if (iw > wid) {
            iw = wid;
        }
        if (ih > hgt) {
            ih = hgt;
        }
        if ((ix + iw) > wid) {
            ix = wid - iw;
        }
        if ((iy + ih) > hgt) {
            iy = hgt - ih;
        }
        newPaper.setSize(wid, hgt);
        newPaper.setImageableArea(ix, iy, iw, ih);
    }
}
 
源代码21 项目: openjdk-jdk9   文件: PSPrinterJob.java
protected double getPhysicalPrintableWidth(Paper p) {
    return p.getImageableWidth();
}
 
源代码22 项目: 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;
    }
 
源代码23 项目: openjdk-8   文件: PSPrinterJob.java
protected double getPhysicalPrintableWidth(Paper p) {
    return p.getImageableWidth();
}
 
源代码24 项目: hottub   文件: WPrinterJob.java
@Override
protected double getPhysicalPageHeight(Paper p) {
    return mPageHeight;
}
 
源代码25 项目: Knowage-Server   文件: ExportHighCharts.java
public static void transformSVGIntoPDF(InputStream inputStream, OutputStream outputStream) throws IOException, DocumentException {

		Rectangle pageSize = PageSize.A4;
		Document document = new Document(pageSize);
		int orientation = PageFormat.PORTRAIT;
		try {
			PdfWriter writer = PdfWriter.getInstance(document, outputStream);
			document.open();

			double a4WidthInch = 8.26771654; // Equals 210mm
			double a4HeightInch = 11.6929134; // Equals 297mm

			Paper paper = new Paper();
			// 72 DPI
			paper.setSize((a4WidthInch * 72), (a4HeightInch * 72));
			// 1 inch margins
			paper.setImageableArea(72, 72, (a4WidthInch * 72 - 144), (a4HeightInch * 72 - 144));
			PageFormat pageFormat = new PageFormat();
			pageFormat.setPaper(paper);
			pageFormat.setOrientation(orientation);

			float width = ((float) pageFormat.getWidth());
			float height = ((float) pageFormat.getHeight());

			PdfContentByte cb = writer.getDirectContent();
			PdfTemplate template = cb.createTemplate(width, height);
			Graphics2D g2 = template.createGraphics(width, height);

			PrintTranscoder prm = new PrintTranscoder();
			TranscoderInput ti = new TranscoderInput(inputStream);
			prm.transcode(ti, null);

			prm.print(g2, pageFormat, 0);
			g2.dispose();

			ImgTemplate img = new ImgTemplate(template);
			img.setWidthPercentage(100);
			img.setAlignment(Image.ALIGN_CENTER);

			document.add(img);

		} catch (DocumentException e) {
			logger.error("Error exporting Highcharts to PDF: " + e);
		}
		document.close();
	}
 
源代码26 项目: 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;
    }
 
源代码27 项目: openjdk-8   文件: WPrinterJob.java
protected double getPhysicalPrintableY(Paper p) {
    return mPrintPhysY;
}
 
源代码28 项目: jdk8u-dev-jdk   文件: WPrinterJob.java
@Override
protected double getPhysicalPageHeight(Paper p) {
    return mPageHeight;
}
 
源代码29 项目: hottub   文件: PSPrinterJob.java
protected double getPhysicalPrintableHeight(Paper p) {
    return p.getImageableHeight();
}
 
源代码30 项目: jdk8u-jdk   文件: WPrinterJob.java
@Override
protected double getPhysicalPrintableHeight(Paper p) {
    return mPrintHeight;
}
 
 类所在包
 同包方法