File Annotations
PSPDFKit supports the reading and creation of file annotations with embedded files. There’s also basic UI support for sharing files embedded in file annotations via Android’s share framework.
Creating File Annotations
FileAnnotation
can be created programmatically in the same way as other supported annotations. The source for the embedded file needs to be wrapped in the EmbeddedFileSource
, and you’ll need to provide at least a DataProvider
serving file data, and its name.
The following example shows how to create a file annotation with data served from application assets:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // Create a file annotation instance. val fileAnnotation = FileAnnotation( // Page index 0. 0, // Page rectangle (in PDF coordinates). RectF(180f, 692f, 212f, 660f), // Embedded file source serving file data from assets. EmbeddedFileSource( AssetDataProvider("FileInAssets.pdf"), "FileInAssets.pdf", "Optional file description" )) // Multiple file icons are supported. fileAnnotation.iconName = FileAnnotation.GRAPH // Annotation color is supported too. fileAnnotation.color = Color.GREEN // Add the created file annotation to the page. document.annotationProvider.addAnnotationToPage(fileAnnotation) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | // Create a file annotation instance. final FileAnnotation fileAnnotation = new FileAnnotation( // Page index 0. 0, // Page rectangle (in PDF coordinates). new RectF(180, 692, 212, 660), // Embedded file source serving file data from assets. new EmbeddedFileSource( new AssetDataProvider("FileInAssets.pdf"), "FileInAssets.pdf", "Optional file description" )); // Multiple file icons are supported. fileAnnotation.setIconName(FileAnnotation.GRAPH); // Annotation color is supported too. fileAnnotation.setColor(Color.GREEN); // Add the created file annotation to the page. document.getAnnotationProvider().addAnnotationToPage(fileAnnotation); |
For additional examples, take a look at the FileAnnotationCreationExample
inside the Catalog app.