public class PrintedPdfDocument extends PdfDocument
This class computes the page width, page height, and content rectangle from the provided print
attributes and these precomputed values can be accessed via getPageWidth()
,
getPageHeight()
, and getPageContentRect()
, respectively. The
startPage(int)
methods creates pages whose
PageInfo
is initialized with the precomputed
values for width, height, and content rectangle.
A typical use of the APIs looks like this:
// open a new document PrintedPdfDocument document = new PrintedPdfDocument(context, printAttributes); // start a page Page page = document.startPage(0); // draw something on the page View content = getContentView(); content.draw(page.getCanvas()); // finish the page document.finishPage(page); . . . // add more pages . . . // write the document content document.writeTo(getOutputStream()); //close the document document.close();
PdfDocument.Page, PdfDocument.PageInfo
Constructor and Description |
---|
PrintedPdfDocument(Context context,
PrintAttributes attributes)
Creates a new document.
|
Modifier and Type | Method and Description |
---|---|
Rect |
getPageContentRect()
Gets the content rectangle.
|
int |
getPageHeight()
Gets the page height.
|
int |
getPageWidth()
Gets the page width.
|
PdfDocument.Page |
startPage(int pageNumber)
Starts a new page.
|
close, finalize, finishPage, getPages, startPage, writeTo
public PrintedPdfDocument(Context context, PrintAttributes attributes)
Note: You must close the document after you are
done by calling PdfDocument.close()
.
context
- Context instance for accessing resources.attributes
- The print attributes.public PdfDocument.Page startPage(int pageNumber)
PageInfo
.
After the page is created you can draw arbitrary content on the page's canvas which you can
get by calling Page.getCanvas()
.
After you are done drawing the content you should finish the page by calling
PdfDocument.finishPage(Page)
. After the page is finished you should no longer access the page or
its canvas.
Note: Do not call this method after PdfDocument.close()
. Also do not call this
method if the last page returned by this method is not finished by calling
PdfDocument.finishPage(Page)
.
pageNumber
- The page number. Must be a non negative.PdfDocument.finishPage(Page)
public int getPageWidth()
public int getPageHeight()
public Rect getPageContentRect()