Package org.apache.pdfbox.pdmodel
Class PDPageable
java.lang.Object
org.apache.pdfbox.pdmodel.PDPageable
Adapter class that implements the
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.- Since:
- Apache PDFBox 1.3.0
- See Also:
-
Field Summary
Fields inherited from interface java.awt.print.Pageable
UNKNOWN_NUMBER_OF_PAGES
Fields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS
-
Constructor Summary
ConstructorsConstructorDescriptionPDPageable
(PDDocument document) Creates aPageable
adapter for the given PDF document using a default printer job returned byPrinterJob.getPrinterJob()
.PDPageable
(PDDocument document, PrinterJob printerJob) Creates aPageable
adapter for the given PDF document and printer job. -
Method Summary
Modifier and TypeMethodDescriptionint
Returns the number of pages in the given PDF document.getPageFormat
(int i) Returns the format of the page at the given index.getPrintable
(int i) Returns aPrintable
for the page at the given index.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.
-
Constructor Details
-
PDPageable
public PDPageable(PDDocument document, PrinterJob printerJob) throws IllegalArgumentException, PrinterException Creates aPageable
adapter for the given PDF document and printer job.- Parameters:
document
- PDF documentprinterJob
- printer job- Throws:
IllegalArgumentException
- if an argument isnull
PrinterException
- if the document permissions prevent printing
-
PDPageable
Creates aPageable
adapter for the given PDF document using a default printer job returned byPrinterJob.getPrinterJob()
.- Parameters:
document
- PDF document- Throws:
IllegalArgumentException
- if the argument isnull
PrinterException
- if the document permissions prevent printing
-
-
Method Details
-
getPrinterJob
Returns the printer job for printing the given PDF document.- Returns:
- printer job
-
getNumberOfPages
public int getNumberOfPages()Returns the number of pages in the given PDF document.- Specified by:
getNumberOfPages
in interfacePageable
- Returns:
- number of pages
-
getPageFormat
Returns the format of the page at the given index.- Specified by:
getPageFormat
in interfacePageable
- Parameters:
i
- page index, zero-based- Returns:
- page format
- Throws:
IndexOutOfBoundsException
- if the page index is invalid
-
getPrintable
Returns aPrintable
for the page at the given index. Currently this method simply returns the underlyingPDPage
object that directly implements thePrintable
interface, but future versions may choose to return a different adapter instance.- Specified by:
getPrintable
in interfacePageable
- Parameters:
i
- page index, zero-based- Returns:
- printable
- Throws:
IndexOutOfBoundsException
- if the page index is invalid
-
print
Prints the page at the given index.- Specified by:
print
in interfacePrintable
- Parameters:
graphics
- printing targetformat
- page formati
- page index, zero-based- Returns:
Printable.PAGE_EXISTS
if the page was printed, orPrintable.NO_SUCH_PAGE
if page index was invalid- Throws:
PrinterException
- if printing failed
-