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.
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.
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.
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.
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.
if let reference = targetPage.addAnnotationReference(source) {
reference.setCustomValue("approved", forKey: "Review_Status")
// source.customValue(forKey: "Review_Status") now returns "approved" too.
}/Popup or /IRT) cannot be shared./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).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.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 method | Result |
|---|---|
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.