Я искал везде, но не могу найти ответ. Самое близкое, что мне удалось найти, это
func saveAnnotations_forever() {
//let documentAttributes = pdfDocument?.documentAttributes
//let attachmentData = pdfDocument?.dataRepresentation()
let currentPage = pdfView.currentPage
let page_index = pdfDocument?.index(for: currentPage!)
let documentURL = self.pdfDocument?.documentURL// URL to your PDF document.
// Create a `PDFDocument` object using the URL.
let pdfDocument = PDFDocument(url: documentURL!)!
// `page` is of type `PDFPage`.
let page = self.pdfDocument!.page(at: page_index!)!
// Extract the crop box of the PDF. We need this to create an appropriate graphics context.
let bounds = page.bounds(for: .mediaBox)
// Create a `UIGraphicsImageRenderer` to use for drawing an image.
let renderer = UIGraphicsImageRenderer(bounds: bounds, format: UIGraphicsImageRendererFormat.default())
// This method returns an image and takes a block in which you can perform any kind of drawing.
let image = renderer.image { (context) in
// We transform the CTM to match the PDF's coordinate system, but only long enough to draw the page.
context.cgContext.saveGState()
context.cgContext.translateBy(x: 0, y: bounds.height)
context.cgContext.concatenate(CGAffineTransform.init(scaleX: 1, y: -1))
page.draw(with: .mediaBox, to: context.cgContext)
context.cgContext.restoreGState()
и т. Д., Чтобы сделать аннотацию и страницу PDF вместе в виде изображения. Тем не менее, я не могу искать по тексту аннотированной страницы (поскольку он был представлен как изображение), и я не могу стереть свои предыдущие аннотации после сохранения. iOS Книга аннотаций работает очень хорошо - я хочу этого добиться, но как?
Заранее спасибо.