java.awt.print.Pageable
, java.awt.print.Printable
public class PDPageable
extends java.lang.Object
implements java.awt.print.Pageable, java.awt.print.Printable
Pageable
and Printable
interfaces for printing a given PDF document. Note that the given PDF
document should not be modified (pages added, removed, etc.) while an
instance of this class is being used.Constructor | Description |
---|---|
PDPageable(PDDocument document) |
Creates a
Pageable adapter for the given PDF document using
a default printer job returned by PrinterJob.getPrinterJob() . |
PDPageable(PDDocument document,
java.awt.print.PrinterJob printerJob) |
Creates a
Pageable adapter for the given PDF document and
printer job. |
Modifier and Type | Method | Description |
---|---|---|
int |
getNumberOfPages() |
Returns the number of pages in the given PDF document.
|
java.awt.print.PageFormat |
getPageFormat(int i) |
Returns the format of the page at the given index.
|
java.awt.print.Printable |
getPrintable(int i) |
Returns a
Printable for the page at the given index. |
java.awt.print.PrinterJob |
getPrinterJob() |
Returns the printer job for printing the given PDF document.
|
int |
print(java.awt.Graphics graphics,
java.awt.print.PageFormat format,
int i) |
Prints the page at the given index.
|
public PDPageable(PDDocument document, java.awt.print.PrinterJob printerJob) throws java.lang.IllegalArgumentException, java.awt.print.PrinterException
Pageable
adapter for the given PDF document and
printer job.document
- PDF documentprinterJob
- printer jobjava.lang.IllegalArgumentException
- if an argument is null
java.awt.print.PrinterException
- if the document permissions prevent printingpublic PDPageable(PDDocument document) throws java.lang.IllegalArgumentException, java.awt.print.PrinterException
Pageable
adapter for the given PDF document using
a default printer job returned by PrinterJob.getPrinterJob()
.document
- PDF documentjava.lang.IllegalArgumentException
- if the argument is null
java.awt.print.PrinterException
- if the document permissions prevent printingpublic java.awt.print.PrinterJob getPrinterJob()
public int getNumberOfPages()
getNumberOfPages
in interface java.awt.print.Pageable
public java.awt.print.PageFormat getPageFormat(int i) throws java.lang.IndexOutOfBoundsException
getPageFormat
in interface java.awt.print.Pageable
i
- page index, zero-basedjava.lang.IndexOutOfBoundsException
- if the page index is invalidpublic java.awt.print.Printable getPrintable(int i) throws java.lang.IndexOutOfBoundsException
Printable
for the page at the given index.
Currently this method simply returns the underlying PDPage
object that directly implements the Printable
interface, but
future versions may choose to return a different adapter instance.getPrintable
in interface java.awt.print.Pageable
i
- page index, zero-basedjava.lang.IndexOutOfBoundsException
- if the page index is invalidpublic int print(java.awt.Graphics graphics, java.awt.print.PageFormat format, int i) throws java.awt.print.PrinterException
print
in interface java.awt.print.Printable
graphics
- printing targetformat
- page formati
- page index, zero-basedPrintable.PAGE_EXISTS
if the page was printed,
or Printable.NO_SUCH_PAGE
if page index was invalidjava.awt.print.PrinterException
- if printing failed