public class PDFDocument
extends java.lang.Object
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 and Description |
---|
PDFDocument()
Creates a new
PDFDocument , initially with no content. |
Modifier and Type | Method and Description |
---|---|
void |
addObject(PDFObject object)
Adds an object to the document.
|
Page |
createPage(java.awt.geom.Rectangle2D bounds)
Creates a new
Page , adds it to the document, and returns
a reference to the Page . |
java.lang.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.
|
java.lang.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(java.lang.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(java.lang.String title)
Sets the title for the document.
|
void |
writeToFile(java.io.File f)
Writes the PDF document to a file.
|
public PDFDocument()
PDFDocument
, initially with no content.public java.lang.String getTitle()
null
.null
).public void setTitle(java.lang.String title)
title
- the title (null
permitted).public java.lang.String getAuthor()
null
.null
).public void setAuthor(java.lang.String author)
author
- the author (null
permitted).public boolean isDebugMode()
public void setDebugMode(boolean debug)
createPage(java.awt.geom.Rectangle2D)
).debug
- the new flag value.public Page createPage(java.awt.geom.Rectangle2D bounds)
Page
, adds it to the document, and returns
a reference to the Page
.bounds
- the page bounds (null
not permitted).public void addObject(PDFObject object)
object
- the object (null
not permitted).public int getNextNumber()
public byte[] getPDFBytes()
public void writeToFile(java.io.File f)
f
- the file.