Fill PDF fields using iTex -:compatibilities of the versions phone's Android OS, Android Studio, Adobe Acrobat

40 Views Asked by At

Using iText, I try to fill the fields in pdf. The pdf is created from MS Word doc file; the fields are added as Text Field Tool in Adobe Acrobat 7. The problem: in the next code the program interrupts execution of pdfFormFill.setValue() (or PdfAcroForm.getAcroForm() - it depends on itext7-core version) and jumps out the function, and over few lines in this code to try{} - see 3 lines under //// marking.

It seems, the code to be correct: but the program jumps to the same line try{ in the end:

       try {
            reader = new PdfReader(inputFile);
            writer = new PdfWriter(new FileOutputStream(outputFile));
            pdfDocument = new PdfDocument(reader, writer);

//// from next line:   (when itext7-core:7.1.9 is used)
            PdfAcroForm form = PdfAcroForm.getAcroForm(pdfDocument, true);
            String currentText = form.getField("TxtField").getValueAsString();
            if (!currentText.isEmpty()) {
                //form.getField("Text1").setValue(s1);     //This call was splitted to check in debug the
                PdfFormField pdfFormField = form.getField("TxtField"); //field's default content-it's OK
//// or from next line:   (when itext7-core:7.1.15 is used)
                pdfFormField.setValue(s1);
            }
            pdfDocument.close();
            Log.d(TAG, "PDF filled successfully!");
        } catch (IOException e) {
            Log.e(TAG, "Error filling PDF: " + e.getMessage());
            e.printStackTrace();
        } finally {
//// prog jumps to next line:
           try {
                if (reader != null) {reader.close();}
                if (writer != null) {writer.close();}

QUESTION: Are there some compatibility requirements between the versions of Android Studio, minimum SDK, phone's Android OS, iText version? If so, which version of iText may be used for the next combination?

Android Studio Hedgehog | 2023.1.1 Patch 2; Min SDK: API 23 Android 6 must be supported; Adobe Acrobat 7 formed the text fields

The pdf file is checked: it is placed on the site, the field may be changed, and pdf with changed fields is printable. Name of the field is checked in debug mode. In Android Studio: Manifest: There are permissions for read and write to pdf; build.gradle: implementation was added and sync; field in pdf with default text works in debug and it's name is known. I also tried to use implementation 'com.itextpdf:itext7-core:7.2.1' implementation 'com.itextpdf:itext7-form:7.2.1' but build shows errors, supposedly for the old Android 6 version.

0

There are 0 best solutions below