Methods Summary |
---|
public void | close()Closes this document. This method should be called after you
are done working with the document. After this call the document
is considered closed and none of its methods should be called.
Note: Do not call this method if the page
returned by {@link #startPage(PageInfo)} is not finished by
calling {@link #finishPage(Page)}.
throwIfCurrentPageNotFinished();
dispose();
|
private void | dispose()
if (mNativeDocument != 0) {
nativeClose(mNativeDocument);
mCloseGuard.close();
mNativeDocument = 0;
}
|
protected void | finalize()
try {
mCloseGuard.warnIfOpen();
dispose();
} finally {
super.finalize();
}
|
public void | finishPage(android.graphics.pdf.PdfDocument$Page page)Finishes a started page. You should always finish the last started page.
Note: Do not call this method after {@link #close()}.
You should not finish the same page more than once.
throwIfClosed();
if (page == null) {
throw new IllegalArgumentException("page cannot be null");
}
if (page != mCurrentPage) {
throw new IllegalStateException("invalid page");
}
if (page.isFinished()) {
throw new IllegalStateException("page already finished");
}
mPages.add(page.getInfo());
mCurrentPage = null;
nativeFinishPage(mNativeDocument);
page.finish();
|
public java.util.List | getPages()Gets the pages of the document.
return Collections.unmodifiableList(mPages);
|
private native void | nativeClose(long nativeDocument)
|
private native long | nativeCreateDocument()
|
private native void | nativeFinishPage(long nativeDocument)
|
private static native long | nativeStartPage(long nativeDocument, int pageWidth, int pageHeight, int contentLeft, int contentTop, int contentRight, int contentBottom)
|
private native void | nativeWriteTo(long nativeDocument, java.io.OutputStream out, byte[] chunk)
|
public android.graphics.pdf.PdfDocument$Page | startPage(android.graphics.pdf.PdfDocument$PageInfo pageInfo)Starts a page using the provided {@link PageInfo}. After the page
is created you can draw arbitrary content on the page's canvas which
you can get by calling {@link Page#getCanvas()}. After you are done
drawing the content you should finish the page by calling
{@link #finishPage(Page)}. After the page is finished you should
no longer access the page or its canvas.
Note: Do not call this method after {@link #close()}.
Also do not call this method if the last page returned by this method
is not finished by calling {@link #finishPage(Page)}.
throwIfClosed();
throwIfCurrentPageNotFinished();
if (pageInfo == null) {
throw new IllegalArgumentException("page cannot be null");
}
Canvas canvas = new PdfCanvas(nativeStartPage(mNativeDocument, pageInfo.mPageWidth,
pageInfo.mPageHeight, pageInfo.mContentRect.left, pageInfo.mContentRect.top,
pageInfo.mContentRect.right, pageInfo.mContentRect.bottom));
mCurrentPage = new Page(canvas, pageInfo);
return mCurrentPage;
|
private void | throwIfClosed()Throws an exception if the document is already closed.
if (mNativeDocument == 0) {
throw new IllegalStateException("document is closed!");
}
|
private void | throwIfCurrentPageNotFinished()Throws an exception if the last started page is not finished.
if (mCurrentPage != null) {
throw new IllegalStateException("Current page not finished!");
}
|
public void | writeTo(java.io.OutputStream out)Writes the document to an output stream. You can call this method
multiple times.
Note: Do not call this method after {@link #close()}.
Also do not call this method if a page returned by {@link #startPage(
PageInfo)} is not finished by calling {@link #finishPage(Page)}.
throwIfClosed();
throwIfCurrentPageNotFinished();
if (out == null) {
throw new IllegalArgumentException("out cannot be null!");
}
nativeWriteTo(mNativeDocument, out, mChunk);
|