PSPDFKit 2.12 Migration Guide

This guide covers migrating to PSPDFKit 2.12 for React Native, after some APIs were moved to the PDFDocument object. These APIs are meant to replace the ones found on the root PSPDFKitView interface and offer the same functionality.

If you’re using any of the APIs below, consider migrating to the equivalent APIs now hosted on the PDFDocument object.

saveCurrentDocument

The API has been renamed to save:

const result = this.pdfRef?.current?.getDocument().save();

getAllUnsavedAnnotations

The API name remains the same:

const result = this.pdfRef?.current
	?.getDocument()
	.getAllUnsavedAnnotations();

getAnnotations

The old getAnnotations API has been split into two APIs, now called getAnnotations and getAnnotationsForPage. getAnnotations supports an optional type parameter. If no parameter is supplied, all annotation types are returned. getAnnotationsForPage requires a page index, with the option to also pass in a type parameter. If no parameter is supplied, all annotation types are returned for the specific page:

const result = this.pdfRef?.current?.getDocument().getAnnotations();
const result = this.pdfRef?.current
	?.getDocument()
	.getAnnotationsForPage(3, 'pspdfkit/ink');

addAnnotation and addAnnotations

These two APIs have been merged into a single API called addAnnotations, taking a single InstantJSON parameter which consists of a Map with an annotations key and an array of annotations as a value. The Instant JSON format key-value pair is also required as part of the Map:

const result = this.pdfRef?.current
	?.getDocument()
	.addAnnotations(instantJSON);

removeAnnotation and removeAnnotations

These two APIs have been merged into a single API called removeAnnotations, taking a single InstantJSON parameter which consists of an Array of annotations to remove:

const result = this.pdfRef?.current
	?.getDocument()
	.removeAnnotations(annotations);

importXFDF

The API name remains the same:

const result = this.pdfRef?.current
	?.getDocument()
	.importXFDF('path/to/XFDF.xfdf');

exportXFDF

The API name remains the same:

const result = this.pdfRef?.current
	?.getDocument()
	.exportXFDF('path/to/XFDF.xfdf');

For more information, refer to the PSPDFKit 2.12 for React Native changelog.