Android fill PDF form

前端 未结 2 767
借酒劲吻你
借酒劲吻你 2021-02-04 08:46

I have .pdf file and multiple forms are there. I want to open my .pdf file, fill the forms and save it from Android development.

Is there any API for A

2条回答
  •  再見小時候
    2021-02-04 08:55

    The native PDF support on current Android platforms (including Android P) doesn't expose any controls for filling forms. 3rd-party PDF SDKs such as PSPDFKit fill this gap and allow programmatic PDF form filling:

    List formFields = document.getFormProvider().getFormFields();
    for (FormField formField : formFields) {
        if (formField.getType() == FormType.TEXT) {
            TextFormElement textFormElement = (TextFormElement) formField.getFormElement();
            textFormElement.setText("Test " + textFormElement.getName());
        } else if (formField.getType() == FormType.CHECKBOX) {
            CheckBoxFormElement checkBoxFormElement = (CheckBoxFormElement)formField.getFormElement();
            checkBoxFormElement.toggleSelection();
        }
    }
    

    (If you click on above link there's also a Kotlin PDF form filling example.)

    Note that most SDKs on the market focus on PDF AcroForms, and not the XFA specification, which has been deprecated in the PDF 2.0 spec.

提交回复
热议问题