public class PDPageable extends Object implements Pageable, 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.UNKNOWN_NUMBER_OF_PAGES
NO_SUCH_PAGE, PAGE_EXISTS
Constructor and 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,
PrinterJob printerJob)
Creates a
Pageable adapter for the given PDF document and
printer job. |
Modifier and Type | Method and Description |
---|---|
int |
getNumberOfPages()
Returns the number of pages in the given PDF document.
|
PageFormat |
getPageFormat(int i)
Returns the format of the page at the given index.
|
Printable |
getPrintable(int i)
Returns a
Printable for the page at the given index. |
PrinterJob |
getPrinterJob()
Returns the printer job for printing the given PDF document.
|
int |
print(Graphics graphics,
PageFormat format,
int i)
Prints the page at the given index.
|
public PDPageable(PDDocument document, PrinterJob printerJob) throws IllegalArgumentException, PrinterException
Pageable
adapter for the given PDF document and
printer job.document
- PDF documentprinterJob
- printer jobIllegalArgumentException
- if an argument is null
PrinterException
- if the document permissions prevent printingpublic PDPageable(PDDocument document) throws IllegalArgumentException, PrinterException
Pageable
adapter for the given PDF document using
a default printer job returned by PrinterJob.getPrinterJob()
.document
- PDF documentIllegalArgumentException
- if the argument is null
PrinterException
- if the document permissions prevent printingpublic PrinterJob getPrinterJob()
public int getNumberOfPages()
getNumberOfPages
in interface Pageable
public PageFormat getPageFormat(int i) throws IndexOutOfBoundsException
getPageFormat
in interface Pageable
i
- page index, zero-basedIndexOutOfBoundsException
- if the page index is invalidpublic Printable getPrintable(int i) throws 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 Pageable
i
- page index, zero-basedIndexOutOfBoundsException
- if the page index is invalidpublic int print(Graphics graphics, PageFormat format, int i) throws PrinterException
print
in interface 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 invalidPrinterException
- if printing failedCopyright © 2002-2015 The Apache Software Foundation. All Rights Reserved.