java.lang.Object | ||
↳ | android.graphics.pdf.PdfDocument | |
↳ | android.print.pdf.PrintedPdfDocument |
This class is a helper for creating a PDF file for given print attributes. It is useful for implementing printing via the native Android graphics APIs.
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 PdfDocument.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();
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Creates a new document.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Gets the content rectangle.
| |||||||||||
Gets the page height.
| |||||||||||
Gets the page width.
| |||||||||||
Starts a new page.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
android.graphics.pdf.PdfDocument
| |||||||||||
From class
java.lang.Object
|
Creates a new document.
Note: You must close the document after you are
done by calling close()
.
context | Context instance for accessing resources. |
---|---|
attributes | The print attributes. |
Gets the content rectangle. This is the area of the page that contains printed data and is relative to the page top left.
Gets the page height.
Gets the page width.
Starts a new page. The page is created using width, height and content
rectangle computed from the print attributes passed in the constructor
and the given page number to create an appropriate PdfDocument.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
finishPage(Page)
. After the page is finished you should no longer
access the page or its canvas.
Note: Do not call this method after close()
.
Also do not call this method if the last page returned by this method
is not finished by calling finishPage(Page)
.
pageNumber | The page number. Must be a positive value. |
---|