Skip to content
DemoSampleAPI ReferenceFAQ

PDF Generation Template Editor

Open-source visual PDF generation engine with customizable templates and developer-friendly APIs.

View on GitHub

Copy and Share Annotations Across Pages ​

Use an independent copy when each page needs its own position or text. Use a shared reference when editing one annotation should update every linked page in the same PDF.

Make an independent copy ​

For an ordinary annotation, copy(to:) (copyToPage: in Objective-C) copies the underlying PDF annotation to the destination. Register the returned wrapper with the destination page. You can then edit either annotation without changing the other, including their custom data.

swift
if let copy = source.copy(to: targetPage) {
    targetPage.updateAndAddAnnotation(copy)
    copy.setCustomValue("pending", forKey: "Review_Status")
}

For form widgets, copying a widget is not the same as creating a new form field: widgets copied within one document can still belong to the same field.

Share the same annotation object ​

Call addAnnotationReference(_:) on the destination CPDFPage. It returns the wrapper for that page, or nil if sharing fails. The reference is already registered; do not call updateAndAddAnnotation(_:) on it.

swift
if let reference = targetPage.addAnnotationReference(source) {
    reference.setCustomValue("approved", forKey: "Review_Status")
    // source.customValue(forKey: "Review_Status") now returns "approved" too.
}
  • The source must be an indirect PDF object that still belongs to a page of the same document. Widgets (including signature fields), popups, and annotations with a popup or reply relationship (/Popup or /IRT) cannot be shared.
  • The pages' /Annots arrays reference the same PDF object. Adding it again to a page that already references it returns the existing wrapper, not a second instance. Removing it from one page removes only that page's reference. There is no longer a unique owning page (/P).
  • Bounds, contents, appearance, and custom properties are shared. The rectangle is not transformed for a destination page's size or rotation. To place the same mark at different coordinates, make an independent copy instead.
  • After an edit, the SDK synchronizes other loaded wrappers. A CPDFView bound to the document redraws affected page views, including preloaded pages outside the viewport. Other wrappers do not emit KVO changes; refresh your own thumbnails and custom renderers separately.
  • Shared identity across pages is a non-standard PDF extension. Other viewers, conversions, and XFDF or JSON export may not preserve it. Prefer independent copies when exchanging annotations with other software.

If the user needs to undo the operation, create the link through the current CPDFListView rather than calling the page API directly. The view tracks the relationship for its undo manager.

CPDFListView methodResult
addAnnotationReference(_:to:)Adds and tracks a reference on another page; returns nil for the source page or if sharing fails.
sharedAnnotationReferences(of:)Returns live wrappers on other pages known to this view. An empty array does not prove that the PDF has no other references.
detachSharedAnnotation(_:)Keeps the shared object on the supplied annotation's page and replaces its known references on other pages with independent copies. Returns the copies, or [] if there is nothing to detach. With undo enabled, detaching is one step: undo removes the copies and relinks the pages.

For example, use listView.addAnnotationReference(source, to: targetPage) to create a tracked link. Undoing deletion can restore a reference to the surviving shared object, and redoing a tracked share preserves the link. If no live reference remains at restore time, Tools can fall back to a captured copy.

Links made directly through CPDFPage and links already present when a document is reopened still synchronize and redraw. They are not automatically tracked by CPDFListView: undoing deletion can restore an independent annotation instead. Synchronizing the other pages does not create an undo step per page. Swift Tools tracks contents edits for ordinary annotations, but not inline FreeText edits or form-widget values through this mechanism.