Search code examples
javapdfbox

How to add button with "icon only" layout to pdf using PDFBOX?


How to add button with layout "icon only" to pdf using PDFBOX? create a button with this properties

I have try this example before, but just can't set to the button properties I want.

[edit]

This the button I created using acrobat.

And This the button i created using PDFBOX

My question is in PDFBOX how to create a button similar to the button created in acrobat?


Solution

  • The desired layout information may be stored in the TP entry of the appearance characteristics dictionary:

    Key Type Value
    TP integer (Optional; pushbutton fields only) A code indicating where to position the text of the widget annotation’s caption relative to its icon:
    0 No icon; caption only
    1 No caption; icon only
    2 Caption below the icon
    3 Caption above the icon
    4 Caption to the right of the icon
    5 Caption to the left of the icon
    6 Caption overlaid directly on the icon
    Default value: 0.

    (ISO 32000-1, Table 189 – Entries in an appearance characteristics dictionary)

    Thus, you may want to try setting the TP entry of the PDAppearanceCharacteristicsDictionary fieldAppearance in the referenced code to 1.