How to implement all format options in fillable forms using PDF BOX 2

101 Views Asked by At

I need to apply the below mentioned format properties on Acrobat DC to my text box fields.

Format_Category

Fields where created using below snippet,

private static void addTBField(PDAcroForm acroForm, PDPage page, String name, float x, float y, float width,
        float height, String toolTip, long fontSize, String fontFamily, long maxLength, Boolean required,
        Boolean multiLine, Boolean checkSpelling, Boolean scrollLongText, Boolean readOnly, Boolean combofChar) {

    try {
        
        PDTextField textBox = new PDTextField(acroForm);
        textBox.setPartialName(name);
        acroForm.getFields().add(textBox);

        
        PDAnnotationWidget widget = textBox.getWidgets().get(0);
        PDRectangle rect = new PDRectangle(x, y, width, height);
        widget.setRectangle(rect);
        widget.setPage(page);

        PDAppearanceCharacteristicsDictionary fieldAppearance = new PDAppearanceCharacteristicsDictionary(
                new COSDictionary());
        if (checkSpelling) {
            checkSpelling = false;
        } else {
            checkSpelling = true;
        }
        if (scrollLongText) {
            scrollLongText = false;
        } else {
            scrollLongText = true;
        }

        widget.setPrinted(true);
        
        page.getAnnotations().add(widget);

        String defaultAppearanceString = "/" + fontFamily + " " + fontSize + " Tf 0 0 0 rg";
        textBox.setDefaultAppearance(defaultAppearanceString);
        textBox.setRequired(required);
        textBox.setAlternateFieldName(toolTip);
        textBox.setComb(combofChar);
        textBox.setDoNotSpellCheck(checkSpelling);
        textBox.setDoNotScroll(scrollLongText);
        textBox.setMaxLen((int) maxLength);
        textBox.setMultiline(multiLine);
        textBox.setQ(PDVariableText.QUADDING_LEFT);

    } catch (IOException e) {
        e.printStackTrace();
    }

}

Need to implement all the format categories available in the above picture using the PDF Box. I am new to this pdf domain. Kindly share the details if any utility is already available inside PDF Box Library.

0

There are 0 best solutions below