public class PrintedPdfDocument
extends PdfDocument
| java.lang.Object | ||
| android.graphics.pdf.PdfDocument | ||
| android.print.pdf.PrintedPdfDocument | ||
该类是为给定的打印属性创建PDF文件的助手。 这对于通过本机Android图形API实现打印非常有用。
这个类从所提供的打印属性计算页的宽度,页高度,和内容矩形和这些预计算的值可以通过以下方式访问getPageWidth() , getPageHeight() ,和getPageContentRect() ,分别。 startPage(int)方法创建页面,其PageInfo使用宽度,高度和内容矩形的预计算值进行初始化。
这些API的典型用法如下所示:
// 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 |
|
|---|---|
PrintedPdfDocument(Context context, PrintAttributes attributes) 创建一个新文档。 |
|
公共方法(Public methods) |
|
|---|---|
Rect |
getPageContentRect() 获取内容矩形。 |
int |
getPageHeight() 获取页面高度。 |
int |
getPageWidth() 获取页面宽度。 |
PdfDocument.Page |
startPage(int pageNumber) 开始一个新页面。 |
继承方法(Inherited methods) |
|
|---|---|
android.graphics.pdf.PdfDocument
|
|
java.lang.Object
|
|
PrintedPdfDocument (Context context, PrintAttributes attributes)
创建一个新文档。
注意:完成后,您必须通过调用 close()来关闭文档。
| 参数(Parameters) | |
|---|---|
context |
Context: Context instance for accessing resources. |
attributes |
PrintAttributes: The print attributes. |
Rect getPageContentRect ()
获取内容矩形。 这是包含打印数据的页面区域,与页面左上角相对。
| 返回(Returns) | |
|---|---|
Rect |
The content rectangle. |
int getPageHeight ()
获取页面高度。
| 返回(Returns) | |
|---|---|
int |
The page height in PostScript points (1/72th of an inch). |
int getPageWidth ()
获取页面宽度。
| 返回(Returns) | |
|---|---|
int |
The page width in PostScript points (1/72th of an inch). |
PdfDocument.Page startPage (int pageNumber)
开始一个新页面。 使用构造函数中传递的打印属性和给定页码计算的宽度,高度和内容矩形创建页面,以创建适当的PageInfo 。
创建页面后,您可以通过调用Page.getCanvas()在页面的画布上绘制任意内容。 完成绘制内容后,您应该拨打finishPage(Page)完成该页面。 页面完成后,您不应再访问该页面或其画布。
注意:请勿在close()之后调用此方法。 如果通过调用finishPage(Page)未完成由此方法返回的最后一页,也请不要调用此方法。
| 参数(Parameters) | |
|---|---|
pageNumber |
int: The page number. Must be a non negative. |
| 返回(Returns) | |
|---|---|
PdfDocument.Page |
A blank page. |
也可以看看: