PDF Generation Template Editor
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.
In Android SDK 3.2.1, CPDFReaderView can copy an annotation to another page or add a reference to the same annotation. Copy when pages need independently editable annotations. Share when changes should appear on all referencing pages.
The examples use source, an ordinary annotation selected on the first page, and target the second page (index 1). Call reader APIs on the main thread. Both operations preserve page coordinates without adjusting them for the target page's size or rotation. Use comparePageGeometry() to check page differences.
CPDFAnnotation copy = readerView.copyAnnotation(source, 1);Editing or deleting copy does not affect the source annotation. If the call returns null, check the target page index and document permissions. To copy across documents, keep both documents open and call the Core API sourcePage.copyAnnot(source, targetPage).
CPDFAnnotation reference = readerView.addAnnotReference(source, 1);
if (reference != null) {
int[] pageIndices = readerView.getAnnotationReferencePages(source);
}reference belongs to the target page but points to the same PDF annotation as source. Changes such as moving the annotation or changing its color appear on all referencing pages. getAnnotationReferencePages() returns zero-based page indices ([0, 1] if only these two pages reference it).
Sharing works within the same document. Widgets, popups, replies, and annotations linked to popups or replies cannot be shared.
| Operation | Reader API | Result on success |
|---|---|---|
| Detach from all pages | readerView.detachAnnotationFromAllPages(source) | The source page keeps the original annotation. Each other referencing page gets an independent copy. |
| Remove one page's reference | readerView.removeAnnotReference(reference) | Only the reference on that page is removed. Removing the last reference deletes the annotation. |
| Delete from all referencing pages | readerView.deleteAnnotationFromAllPages(source) | The annotation is removed from every page that references it. |
After detaching, reselect or retrieve the copy on the target page before editing it; the old reference is no longer valid. These reader operations support undo and redo when CPDFUndoManager is enabled. If deletion from all pages returns false, some references may already have been removed.
Pass the annotation object owned by the page you want to modify. For example, pass the reference returned by targetPage.addAnnotReference(source), not source, when removing the target page's reference.
| Operation | Core API | Scope |
|---|---|---|
| Remove one reference | targetPage.removeAnnotReference(reference) | Removes only the target page's reference, not its reply chain. The removed reference becomes invalid. |
| Delete a page annotation | page.deleteAnnotation(annotation) | Deletes the annotation and its replies from that page, not from every referencing page. |
Core has no single call for detaching or deleting across all pages. Keep track of the referencing pages and check each operation for failure. To detach, keep the original on one page, call copyAnnot() to create an independent copy on each other page, and remove that page's old reference only after the copy succeeds. To delete across all pages, retrieve each page's own reference and remove it individually.