org.apache.pdfbox.pdmodel
Class PDPageable

java.lang.Object
  extended by org.apache.pdfbox.pdmodel.PDPageable
All Implemented Interfaces:
Pageable, Printable

public class PDPageable
extends Object
implements Pageable, Printable

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:
PDFBOX-788

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
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 job)
          Creates a Pageable adapter for the given PDF document and printer job.
 
Method Summary
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PDPageable

public PDPageable(PDDocument document,
                  PrinterJob job)
           throws IllegalArgumentException,
                  PrinterException
Creates a Pageable adapter for the given PDF document and printer job.

Parameters:
document - PDF document
job - printer job
Throws:
IllegalArgumentException - if an argument is null
PrinterException - if the document permissions prevent printing

PDPageable

public PDPageable(PDDocument document)
           throws IllegalArgumentException,
                  PrinterException
Creates a Pageable adapter for the given PDF document using a default printer job returned by PrinterJob.getPrinterJob().

Parameters:
document - PDF document
Throws:
IllegalArgumentException - if the argument is null
PrinterException - if the document permissions prevent printing
Method Detail

getPrinterJob

public 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 interface Pageable
Returns:
number of pages

getPageFormat

public PageFormat getPageFormat(int i)
                         throws IndexOutOfBoundsException
Returns the format of the page at the given index.

Specified by:
getPageFormat in interface Pageable
Parameters:
i - page index, zero-based
Returns:
page format
Throws:
IndexOutOfBoundsException - if the page index is invalid

getPrintable

public Printable getPrintable(int i)
                       throws IndexOutOfBoundsException
Returns a 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.

Specified by:
getPrintable in interface Pageable
Parameters:
i - page index, zero-based
Returns:
printable
Throws:
IndexOutOfBoundsException - if the page index is invalid

print

public int print(Graphics graphics,
                 PageFormat format,
                 int i)
          throws PrinterException
Prints the page at the given index.

Specified by:
print in interface Printable
Parameters:
graphics - printing target
format - page format
i - page index, zero-based
Returns:
Printable.PAGE_EXISTS if the page was printed, or Printable.NO_SUCH_PAGE if page index was invalid
Throws:
PrinterException - if printing failed


Copyright © 2002-2012 The Apache Software Foundation. All Rights Reserved.