Since iOS 27.0, PDFPage.copy() seems to share annotations with the original page.
When I remove annotations from the copied page, the annotations on the original page are also removed.
Environment
- Reproduces: iOS 27.0 (Simulator), iOS 27.2 (Simulator), iPadOS 27.2.1 (iPad 9th generation)
- Does not reproduce: iOS 26.4, iOS 26.5, iPadOS 26.7.2
- Xcode ____, Swift 5 mode
Steps to reproduce
- Prepare a PDF whose first page already has annotations saved in the file (e.g. ink or stamp annotations).
- Load it with
PDFDocument(data:). - Without displaying page 0 and without reading
page.annotations, callcopy()on page 0. - Remove all annotations from the copied page.
- Check the annotations of the original page 0.
import PDFKit
func reproduce(pdfData: Data) {
guard let document = PDFDocument(data: pdfData),
let original = document.page(at: 0),
let copied = original.copy() as? PDFPage else { return }
// Do NOT touch original.annotations before copy()
for annotation in copied.annotations {
copied.removeAnnotation(annotation)
}
print("original annotations:", original.annotations.count)
// iOS 26.x : the original count is kept
// iOS 27.x : 0 (the annotations on the original page are gone)
}
Expected result
The original page keeps its annotations. The copy should be independent of the original.
Actual result
The original page loses its annotations. When the document is saved with dataRepresentation(), the annotations on page 1 are either missing or written with an empty appearance stream (/BBox [0 0 0 0], content q Q).
Additional notes
- The annotations are not lost if page 0 is rendered, or if
original.annotationsis read once, before callingcopy(). It looks like the copy shares the annotation storage while the annotations are still lazily loaded. - The original annotations are removed even if the copied page is never inserted into the document.
- Workaround: create a separate
PDFDocumentfrom the same data and use its page instead ofcopy().
Is this an intended behavior change in iOS 27, or a bug?
Let’s focus this discussion on your other thread.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"