首页 > 解决方案 > 添加可点击的图章注释 PSPDFKit

问题描述

我正在使用PSPDFKit来处理 PDF 文件。我的应用程序的重点是在 PDF 上添加图章,效果很好。但是,我想让我的图章可以点击,这样我就可以从另一个 PDF 查看器(例如 Acrobat)中点击它。

我虽然有很多方法可以做到这一点,但唯一可行的方法是让我的邮票可点击。

感谢 PSPDFKit UI ,我正在添加一个图章,但我正在实现我的自定义逻辑以处理注释创建。

    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());
                }
            }
        });

在此先感谢,如果这个问题似乎是广泛的评论,我试图做的就是尽可能简单地理解^^

诚挚的,马修

标签: androidpdfpspdfkitpdf-annotations

解决方案


推荐阅读