Package org.apache.pdfbox.pdmodel
Class PDPageable
- java.lang.Object
-
- org.apache.pdfbox.pdmodel.PDPageable
-
- All Implemented Interfaces:
java.awt.print.Pageable
,java.awt.print.Printable
public class PDPageable extends java.lang.Object implements java.awt.print.Pageable, java.awt.print.Printable
Adapter class that implements thePageable
andPrintable
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:
- PDFBOX-788
-
-
Constructor Summary
Constructors Constructor Description PDPageable(PDDocument document)
Creates aPageable
adapter for the given PDF document using a default printer job returned byPrinterJob.getPrinterJob()
.PDPageable(PDDocument document, java.awt.print.PrinterJob printerJob)
Creates aPageable
adapter for the given PDF document and printer job.
-
Method Summary
All Methods Instance Methods Concrete Methods 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 aPrintable
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.
-
-
-
Constructor Detail
-
PDPageable
public PDPageable(PDDocument document, java.awt.print.PrinterJob printerJob) throws java.lang.IllegalArgumentException, java.awt.print.PrinterException
Creates aPageable
adapter for the given PDF document and printer job.- Parameters:
document
- PDF documentprinterJob
- printer job- Throws:
java.lang.IllegalArgumentException
- if an argument isnull
java.awt.print.PrinterException
- if the document permissions prevent printing
-
PDPageable
public PDPageable(PDDocument document) throws java.lang.IllegalArgumentException, java.awt.print.PrinterException
Creates aPageable
adapter for the given PDF document using a default printer job returned byPrinterJob.getPrinterJob()
.- Parameters:
document
- PDF document- Throws:
java.lang.IllegalArgumentException
- if the argument isnull
java.awt.print.PrinterException
- if the document permissions prevent printing
-
-
Method Detail
-
getPrinterJob
public java.awt.print.PrinterJob 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 interfacejava.awt.print.Pageable
- Returns:
- number of pages
-
getPageFormat
public java.awt.print.PageFormat getPageFormat(int i) throws java.lang.IndexOutOfBoundsException
Returns the format of the page at the given index.- Specified by:
getPageFormat
in interfacejava.awt.print.Pageable
- Parameters:
i
- page index, zero-based- Returns:
- page format
- Throws:
java.lang.IndexOutOfBoundsException
- if the page index is invalid
-
getPrintable
public java.awt.print.Printable getPrintable(int i) throws java.lang.IndexOutOfBoundsException
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 interfacejava.awt.print.Pageable
- Parameters:
i
- page index, zero-based- Returns:
- printable
- Throws:
java.lang.IndexOutOfBoundsException
- if the page index is invalid
-
print
public int print(java.awt.Graphics graphics, java.awt.print.PageFormat format, int i) throws java.awt.print.PrinterException
Prints the page at the given index.- Specified by:
print
in interfacejava.awt.print.Printable
- 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:
java.awt.print.PrinterException
- if printing failed
-
-