Annotate Images (Image Documents)

While it has always been possible to annotate images in PSPDFKit, doing so previously required some extra code. You had to convert an image to PDF, be sure to update the annotation tools and UI to only show relevant options, and extract the image data back when a save occurred.

In PSPDFKit 2.7.0 for Windows, we added support for opening images just like a PDF using PDFView.Controller.ShowDocumentAsync. We also added a Format value to the document export options, meaning it’s possible to save any document back to a PNG, JPEG, or TIFF image.

Opening an image with PDFView.Controller.ShowDocumentAsync will do so in accordance with the image document standard. Image documents allow the user to add, edit, or delete annotations even after saving and reopening, meaning you can treat images just like PDFs.

ℹ️ Note: This feature requires the Image Documents component to be enabled in your license.

If you need to use an image as an annotation in another document, see our guide on image annotations.

Image Formats

You can initialize an image document by using PDFView.Controller.ShowDocumentAsync and pointing the DocumentSource to an image file. Image documents support the PNG, JPEG, and TIFF file formats:

// Open a `Picker` so the user can choose a document.
var file = await FileUtils.PickFileToOpenAsync(new[]{".png", ".jpg", ".jpeg", ".tif", ".tiff"});
if (file == null) return;

var documentSource = DocumentSource.CreateFromStorageFile(file);
await PDFView.Controller.ShowDocumentAsync(documentSource);

Exporting

Image documents can be exported in the same way as PDFs, allowing control over where and in what format an image document is saved. More information on saving to different target mediums can be found in the Opening and Saving PDFs guide.

To keep the same image format as the original, use the Original format in the DocumentExportOptions:

var file = PDFView?.Document?.DocumentSource?.GetFile();
if (file == null) return;

await PDFView.Document.ExportAsync(
	 file,
	 new DocumentExportOptions
	 {
		  // Note that if the original document is an image format,
		  // then only the first page will be exported.
		  Format = PSPDFKitFoundation.Document.Format.Original
	 });

With the same ExportAsync API, it’s possible to export the open image or document to a different file type than the original. To do so, set the format desired in DocumentExportOptions:

var file = await FileUtils.PickFileToSaveAsync(".pdf");
if (file == null) return;

await PDFView.Document.ExportAsync(
	 file,
	 new DocumentExportOptions
	 {
		  Format = PSPDFKitFoundation.Document.Format.Pdf
	 });