Here at PSPDFKit, we want to provide users with an enhanced experience when annotating images. We believe that users should be able to open their images at any time and have no problem editing the annotations that were created in the past, just like with a PDF document.
We have built a standard leveraging the open ISO 16684-1:2012 extensible metadata platform (XMP) specification to save various kinds of information, which can be drawn upon when opening images via PSPDFKit. To add to that, in this guide we will be opening up our XMP format so that anybody can parse the metadata and create an editable PDF that can be saved and opened at later date.
The XMP data within an image file holds all the necessary information to be able to compile an editable PDF. This PDF represents the original image with annotations overlaid. To compile the editable PDF, we hold four important pieces of information. This information is held in the pspdf namespace, and as such, all attributes will have a prefix of pspdf:.
Image Document Version
To ensure that we can update the Image Documents standard in the future, we have included a version number. That way, if we do make changes to the XMP format, we can identify the required parser:
The document tag holds a full copy of the PDF document, but it omits one important piece of information: the original image. To retain the quality and size of the input image, it was decided that the original image should not be stored within the PDF data and instead appended upon opening. Additionally, by holding the entire PDF document, the standard has the ability to build upon the many features of the PDF specification.
The PDF document is encoded in base64, which will mitigate any ASCII representation issues in XMP:
As we have decided not to hold the original image in the PDF document, and since the image displayed in the main image file will be a render of the current representation with annotations, we have to hold the original image in the metadata for recall at a later date. This data will be held in base64 and will be a direct copy of the original image data. With this data, along with PDF data, we can compile an up-to-date PDF representation of the annotated image.
We needed a way of checking if the image has changed in any way without us knowing, because it is still possible to edit images externally with an image editor. For this reason, we added a CRC32 checksum of the image shown in a standard image viewer. The checksum data can be checked when reopening the file to ensure no edits have been made. At this point, the developer can then decide to either disregard the XMP data and create a new image document or show an error to the user and advise them of what to do in this situation.
The PSPDFKit SDK is a framework that allows you to view, annotate, sign, and fill PDF forms on iOS, Android, Windows, macOS, and Web.
PSPDFKit Instant adds real-time collaboration features to seamlessly share, edit, and annotate PDF documents.