Module org.jfree.pdf
Package org.jfree.pdf

# Class PDFDocument

java.lang.Object
org.jfree.pdf.PDFDocument

public class PDFDocument extends Object
Represents a PDF document. The focus of this implementation is to allow the use of the `PDFGraphics2D` class to generate PDF content, typically in the following manner:

`PDFDocument pdfDoc = new PDFDocument();
` `Page page = pdfDoc.createPage(new Rectangle(612, 468));
` `PDFGraphics2D g2 = page.getGraphics2D();
` `g2.setPaint(Color.RED);
` `g2.draw(new Rectangle(10, 10, 40, 50));
` `pdfDoc.writeToFile(new File("demo.pdf"));
`

The implementation is light-weight and works very well alongside packages such as JFreeChart and Orson Charts.

## Constructor Summary

Constructors
Constructor
Description
`PDFDocument()`
Creates a new `PDFDocument`, initially with no content.

## Method Summary

Modifier and Type
Method
Description
`Page`
`createPage(Rectangle2D bounds)`
Creates a new `Page`, adds it to the document, and returns a reference to the `Page`.
`String`
`getAuthor()`
Returns the author for the document.
`int`
`getNextNumber()`
Returns a new PDF object number and increments the internal counter for the next PDF object number.
`byte[]`
`getPDFBytes()`
Returns a byte array containing the encoding of this PDF document.
`String`
`getTitle()`
Returns the title for the document.
`boolean`
`isDebugMode()`
Returns the debug mode flag that controls whether or not the output stream is filtered.
`void`
`setAuthor(String author)`
Sets the author for the document.
`void`
`setDebugMode(boolean debug)`
Sets the debug MODE flag (this needs to be set before any call to `createPage(java.awt.geom.Rectangle2D)`).
`void`
`setTitle(String title)`
Sets the title for the document.
`void`
`writeToFile(File f)`
Writes the PDF document to a file.

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Constructor Details

### PDFDocument

public PDFDocument()
Creates a new `PDFDocument`, initially with no content.

## Method Details

### getTitle

public String getTitle()
Returns the title for the document. The default value is `null`.

Returns:
  The title for the document (possibly `null`).

### setTitle

public void setTitle(String title)
Sets the title for the document.

Parameters:
  `title` - the title (`null` permitted).

### getAuthor

public String getAuthor()
Returns the author for the document. The default value is `null`.

Returns:
  The author for the document (possibly `null`).

### setAuthor

public void setAuthor(String author)
Sets the author for the document.

Parameters:
  `author` - the author (`null` permitted).

### isDebugMode

public boolean isDebugMode()
Returns the debug mode flag that controls whether or not the output stream is filtered.

Returns:
  The debug flag.
Since:
  1.4

### setDebugMode

public void setDebugMode(boolean debug)
Sets the debug MODE flag (this needs to be set before any call to `createPage(java.awt.geom.Rectangle2D)`).

Parameters:
  `debug` - the new flag value.
Since:
  1.4

### createPage

public Page createPage(Rectangle2D bounds)
Creates a new `Page`, adds it to the document, and returns a reference to the `Page`.

Parameters:
  `bounds` - the page bounds (`null` not permitted).
Returns:
  The new page.

### getNextNumber

public int getNextNumber()
Returns a new PDF object number and increments the internal counter for the next PDF object number. This method is used to ensure that all objects in the document are assigned a unique number.

Returns:
  A new PDF object number.

### getPDFBytes

public byte[] getPDFBytes()
Returns a byte array containing the encoding of this PDF document.

Returns:
  A byte array containing the encoding of this PDF document.

### writeToFile

public void writeToFile(File f)
Writes the PDF document to a file. This is not a robust method, it exists mainly for the demo output.

Parameters:
  `f` - the file.