I am using PSPDFKit to manipulate PDF files. The point of my application is to add a stamp onto a PDF, which works perfectly fine. But, I would like to make my stamps clickable so I might click on it from another PDF Viewer (such as Acrobat).
I though of many ways to do it but the only one plausible is to make my stamps clickables.
I'm adding a stamp thanks to PSPDFKit UI but I'm implementing my custom logic in order to handle the annotation creation.
pdfDocument.getAnnotationProvider().addOnAnnotationUpdatedListener(new AnnotationProvider.OnAnnotationUpdatedListener(){
//I check if this is the first Stamp annotation I created for this session.
//If it isn't I just move the previous one to the new point
//Each time I open my PDF I can add only one stamp annotation
@Override
public void onAnnotationCreated(@NonNull com.pspdfkit.annotations.Annotation annotation) {
if(annotation instanceof StampAnnotation){
if(currentAnnotation != null){
if(fragment.getDocument() != null) {
fragment.getDocument().getAnnotationProvider().removeAnnotationFromPage(annotation);
fragment.notifyAnnotationHasChanged(annotation);
}
}
else{
((StampAnnotation) annotation).setSubtext(currentImageName);
currentAnnotation = annotation;
}
/*
Trying to find how to make currentAnnotation a clickable annotation
I used the subtext attribute to store some data relevant for my action.
I also looked up for LinkAnnotations but I can't figure how they work out
*/
}
}
//I check if the annotation is a Stamp.
//If it is, I add it to annotations to remove from my app's business logic
@Override
public void onAnnotationRemoved(@NonNull com.pspdfkit.annotations.Annotation annotation) {
if(annotation instanceof StampAnnotation){
runOnUiThread(() ->Toast.makeText(PSPdfFloorPlanActivity.this, "Annotation removed " + ((StampAnnotation) annotation).getSubtext(), Toast.LENGTH_SHORT).show());
if(annotation.equals(currentAnnotation)){
currentAnnotation = null;
}
removedAnnotationsImagesNames.add(((StampAnnotation) annotation).getSubtext());
}
}
});
Thanks in advance, if the question seems to broad comment it I'm trying to make is as simple as possible to understand ^^
Cordially, Matthieu