Print only fillable pdf fields not annotations as well

Product: Android native sdk

Product Version: 9.2.3

Please give a brief summary of your issue:
Cannot print only fillable pdf fields.

Please describe your issue and provide steps to reproduce it:
I’m trying to print just the fillable pdf fields not all the other annotations that have been included or drawn on. When doing this the print job includes all annotations not just fillable fields

val printContent =
            0 or Print.PRINT_CONTENT_DOCUMENT_BIT or Print.PRINT_CONTENT_ANNOTATION_BIT
Print.startPrintJob(
        activity,
        activity?.getString(R.string.app_name),
        pdfDoc,
        printContent,
        false
 )

How can I achieve that?

Please provide a link to a minimal sample where the issue is reproducible:

Hello, I’m Ron, an automated tech support bot :robot:

While you wait for one of our customer support representatives to get back to you, please check out some of these documentation pages:

Guides:APIs:Forums:

Hi @seth.pacheco ,

In order to do this you will need to create a copy of your PDF with all the annotations that’s not a fillable fields removed.

Thanks,
Andrew.

Ok @ama. How would I do this exactly? on the iOS side there is a function

toolManager.annotationManager.removeAllAnnotations()

which removes all the annotations that are not fillable fields. Is there nothing like this in the Android sdk?

What is the best way to remove annotation fields that aren’t fillable? I have the data object from our server of all annotations with the appropriate id but cannot find the best way to remove solely for share/print and not the viewing of the document

Hi @seth.pacheco

You can achieve the same on Android by first creating a copy of your document and then modify it using the following sample before print

            AnnotUtils.traverseAnnots(pdfDoc, new AnnotUtils.AnnotVisitor() {
                @Override
                public void visit(@NonNull Annot annot) {
                    try {
                        if (Annot.e_Widget != annot.getType()) {
                            Page page = annot.getPage();
                            page.annotRemove(annot);
  
                        }
                    } catch (PDFNetException e) {
                    }
                }
            });

The rest would be the same PDF with all the non-fillable annotations being removed. Next you can print that copy of the document and discard the copy it at the end if you wish. Could you please give this a try to see if it works for you?

Thanks,
Andrew.

Hi Seth,

It appears we gave you the incorrect sample for this ticket, please see the correct sample below:

val pdfDoc = pdfViewCtrlTabHostFragment?.currentPdfViewCtrlFragment?.pdfDoc
val tempPath = "/data/data/com.canopytax.practitioner/files/testing.pdf"
pdfDoc!!.save(tempPath, SDFDoc.SaveMode.NO_FLAGS, null)

val pdfDocTemp = PDFDoc(tempPath)
val pageIterator = pdfDocTemp.pageIterator
while(pageIterator.hasNext()) {
    val page = pageIterator.next()
    if (page!!.isValid) {
        val annotationCount = page.numAnnots
        for (a in annotationCount - 1 downTo 0) {
            val annot = page.getAnnot(a)
            if (annot != null && annot.isValid) {
                if (Annot.e_Widget != annot.type) {
                    page.annotRemove(annot)
                }
            }
        }
    }
}

val printContent =
    0 or Print.PRINT_CONTENT_DOCUMENT_BIT or Print.PRINT_CONTENT_ANNOTATION_BIT
Print.startPrintJob(
    activity,
    activity?.getString(R.string.app_name),
    pdfDocTemp,
    printContent,
    false
)

Please let us know if this resolves your issue.

Best Regards,
Eamon