AnnotationProvider protocol defines methods for getting and setting annotations. PSPDFKit is structured in such a way that a document can have several of these providers. Each document has one or more instances of
PDFDocumentProvider, each of which has one
AnnotationManager, which, in turn, contains one or more annotation provider/s.
By default, the
annotationProviders array simply contains the
fileAnnotationProvider. This provider will parse the PDF and load annotations from it, and it’ll also handle saving back into the PDF, subject to the value of
The file annotation provider also handles our internal
NSCoder-based format for saving and loading annotations. This is an internal file format, and it shouldn’t be used for long-term storage of annotations. PSPDFKit usually supports loading and saving using this format at least one version back. So, for example, v4 can load v3 but not v2 or v5.
Annotations are only useful if they can be shared across multiple clients. To do this, there are several options available, detailed below.
PSPDFKit Instant is our in-house syncing solution for seamless collaboration for PSPDFKit-powered apps. It not only takes care of near-real-time annotation syncing, but it also manages file downloads and other metadata, such as bookmarks (which will be available in a future update). Instant is highly optimized for PSPDFKit and uses a deep API integration, which is faster and more reliable than anything you can achieve writing your own code.
Instant JSON is our approach to bringing annotations into a modern format. It’s compatible with our SDK on all platforms while keeping all important properties to make the Instant JSON spec work with PDFs. It’s fully documented and supports long-term storage. Please take a look at the Instant JSON guide for more details.
XFDF is an XML-like standard from Adobe XFDF used for encoding annotations and forms. It’s compatible with Adobe Acrobat and several other third-party frameworks. PSPDFKit supports both reading and writing XFDF and also offers a
XFDFAnnotationProvider subclass that will save/load annotations to/from XFDF automatically. There are several examples in PSPDFKit Catalog and in our XFDF Support guide that show the exact use. XFDF can be used in combination with
AESCryptoOutputStream to build an encrypted annotation store. Please note that XFDF is problematic for binary attachments such as sound annotations and images, which are saved inline and might make a file large.
AnnotationProvider protocol can also be implemented to have fully custom saving and loading. This is an advanced method, and we recommend using PSPDFKit Instant instead. However, if you have a specific use case, take a look at the
PDFContainerAnnotationProvider subclass. The latter implements several of the harder-to-get-right details of the annotation provider protocol.