public class PDFDocument extends Object implements Serializable
The typical flow for use of the PDF library is as follows:
// Create a PDF document, a page in the document, and get that page's PDFCanvas
PDFDocument pdfDoc = new PDFDocument();
PDFPage page = new PDFPage(PageFormat.LETTER);
pdfDoc.add(page);
PDFCanvas pdfCanvas = page.getCanvas();
// do drawing commands on the PDFCanvas associated with the page as you would on any other Canvas
myDrawDesign(pdfCanvas);
// add and draw on other pages as desired
// write the PDF content for the page to a file
BufferedOutputStream fileStream = new BufferedOutputStream(new FileOutputStream(file));
pdfDoc.write(outStream);
fileStream.flush();
fileStream.close();
Modifier and Type | Field and Description |
---|---|
static int |
FULLSCREEN
This page mode indicates that when the document is opened, it is displayed in full-screen-mode.
|
static String[] |
PDF_PAGE_MODES
These map the page modes just defined to the pagemodes setting of PDF.
|
static int |
USENONE
This page mode indicates that the document should be opened just with the page visible.
|
static int |
USEOUTLINES
This page mode indicates that the Outlines should also be displayed when the document is opened.
|
static int |
USETHUMBS
This page mode indicates that the Thumbnails should be visible when the document first opens.
|
Constructor and Description |
---|
PDFDocument()
This creates a PDF document with the default pagemode
|
PDFDocument(int pagemode)
This creates a PDF document
|
Modifier and Type | Method and Description |
---|---|
int |
add(PDFObject obj)
This adds a top level object to the document.
|
PDFFont |
getFont(String type,
Typeface typeface)
This returns a font of the specified type and typeface.
|
PDFOutline |
getOutline() |
PDFPage |
getPage(int page)
This returns a specific page
|
PDFInfo |
getPDFInfo()
Get the PDFInfo object, which contains author, title, keywords, etc
|
void |
setPDFInfo(PDFInfo info)
Set the PDFInfo object, which contains author, title, keywords, etc
|
void |
write(OutputStream os)
This writes the document to an OutputStream.
|
public static final int USENONE
This page mode indicates that the document should be opened just with the page visible. This is the default
public static final int USEOUTLINES
This page mode indicates that the Outlines should also be displayed when the document is opened.
public static final int USETHUMBS
This page mode indicates that the Thumbnails should be visible when the document first opens.
public static final int FULLSCREEN
This page mode indicates that when the document is opened, it is displayed in full-screen-mode. There is no menu bar, window controls nor any other window present.
public static final String[] PDF_PAGE_MODES
These map the page modes just defined to the pagemodes setting of PDF.
public PDFDocument()
This creates a PDF document with the default pagemode
public PDFDocument(int pagemode)
This creates a PDF document
pagemode
- an int, determines how the document will present itself to the viewer when it first opens.public int add(PDFObject obj)
Once added, it is allocated a unique serial number, as well as a unique name relevant to the object type (e.g., /Image47 or /Pattern19)
Note: Not all objects are added directly using this method. Some objects which have Kids (in PDF sub-objects or children are called Kids) will have their own add() method, which will call this one internally.
obj
- The PDFObject to add to the documentpublic PDFPage getPage(int page)
This returns a specific page
page
- page number to returnpublic PDFOutline getOutline()
public PDFFont getFont(String type, Typeface typeface)
type
- PDF Font Type - usually "/Type1"typeface
- Android typefacepublic void setPDFInfo(PDFInfo info)
Set the PDFInfo object, which contains author, title, keywords, etc
info
- a PDFInof objectpublic PDFInfo getPDFInfo()
Get the PDFInfo object, which contains author, title, keywords, etc
public void write(OutputStream os) throws IOException
Note: You can call this as many times as you wish, as long as the calls are not running at the same time.
Also, objects can be added or amended between these calls.
Also, the OutputStream is not closed, but will be flushed on completion. It is up to the caller to close the stream.
os
- OutputStream to write the document toIOException
- on error