Uploaded image for project: 'PDFBox'
  1. PDFBox
  2. PDFBOX-4252

PDChoice related bugs and issues

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Open
    • Major
    • Resolution: Unresolved
    • 2.0.10
    • None
    • AcroForm

    Description

      There are several issues related to either PDListBox or PDComboBox that are still not fixed in 2.0.10, I am going to put them in this one case, let me know if they need to be broken into separate tickets. Thanks.

      1. When I attempt to set value to a PDListBox whose 'Top Index' is greater than 0 (as in top index 3.pdf), I always receive the following exception:

      java.lang.IllegalStateException: Error: You must call beginText() before calling endText.
      	at org.apache.pdfbox.pdmodel.PDPageContentStream.endText(PDPageContentStream.java:381) ~[pdfbox-2.0.10.jar:2.0.10]
      ...
      

      I tracked it down to a for loop at the end of the private method insertGeneratedListboxAppearance in the class AppearanceGeneratorHelper:

       for (int i = topIndex; i < numOptions; i++)
              {
                 
                  if (i == topIndex)
                  {
                      yTextPos = yTextPos - font.getFontDescriptor().getAscent() / FONTSCALE * fontSize;
                  }
                  else
                  {
                      yTextPos = yTextPos - font.getBoundingBox().getHeight() / FONTSCALE * fontSize;
                      contents.beginText();
                  }
      
                  contents.newLineAtOffset(contentRect.getLowerLeftX(), yTextPos);
                  contents.showText(options.get(i));
      
                  if (i - topIndex != (numOptions - 1))
                  {
                      contents.endText();
                  }
              }
      

      The last 'if' clause, when topIndex == 0, this makes sense, which is to NOT call endText if we are at the last option because the private method insertGeneratedAppearance which calls insertGeneratedListboxAppearance would later call endText once again. If topIndex > 0, the condition in this 'if' clause would always be true (since i can never be greater than numOptions - 1), as a result, endText is called every time in this 'for' loop, so after the method returns and the next endText is called, we receive the exception. If I change that to

       if (i != (numOptions - 1))
                  {
                      contents.endText();
                  }
      

      things would start to work again.

      2. a related issue, suppose I have a list box with top index equals to 0 and too many options for the list box to show all of them at once (as in top index 0.pdf). When I select an option that is not visible with a top index of 0 (in order to see it, we need to scroll the list box down), unlike Acrobat which would adjust the top index so the selected option would be visible, PDFBox does not recalculate the top index and would stick with the initial value of 0. I suppose, If we fix item #1 above (i.e. top index greater than 0), the opposite would also be true (if top index is say 6 and you select the first item which is not visible unless you scroll the list box up). This would make it useless if I flatten the document since there is no way I can see the selected option (see top index 0 flattened.pdf). It is also next to impossible to see the selected option even if I do not flatten it (see top index 0 with index 4 set as selected.pdf). I would expect PDFBox to recalculate the top index so that at least the first selected option is visible (if there are additional selected options, show more options when possible)

      3. When flattening, drop down list or PDComboBox with options that have export values only shows the export values instead of the label. This not a problem for the list box. (e.g. form: test listbox and droplist export values.pdf, after flattening: test listbox_and_droplist export values flattened.pdf). I would expect the drop down list to behave the same as list box (i.e. when flattened, it should also show the label instead of the export value.)

      Attachments

        1. test listbox_and_droplist export values flattened.pdf
          13 kB
          Xin Lin
        2. test listbox and droplist export values.pdf
          16 kB
          Xin Lin
        3. top index 0.pdf
          11 kB
          Xin Lin
        4. top index 0 flattened.pdf
          13 kB
          Xin Lin
        5. top index 0 with index 4 set as selected.pdf
          13 kB
          Xin Lin
        6. top index 3.pdf
          11 kB
          Xin Lin

        Activity

          People

            Unassigned Unassigned
            xin.lin Xin Lin
            Votes:
            2 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated: