Xin Lin created PDFBOX-4252:
-------------------------------

             Summary: PDChoice related bugs and issues
                 Key: PDFBOX-4252
                 URL: https://issues.apache.org/jira/browse/PDFBOX-4252
             Project: PDFBox
          Issue Type: Bug
          Components: AcroForm
            Reporter: Xin Lin
         Attachments: test listbox and droplist export values.pdf, test 
listbox_and_droplist export values flattened.pdf, top index 0 flattened.pdf, 
top index 0 with index 4 set as selected.pdf, top index 0.pdf, top index 3.pdf

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:
{noformat}
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]
...
{noformat}
I tracked it down to a for loop at the end of the private method 
insertGeneratedListboxAppearance in the class AppearanceGeneratorHelper:
{code:java}
 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();
            }
        }
{code}
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 never come true, 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
{code:java}
 if (i != (numOptions - 1))
            {
                contents.endText();
            }
{code}
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 needs to be scrolled down to see, unless 
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. 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 index 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 when flattened also show the label instead of 
the export value.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to