[ https://issues.apache.org/jira/browse/PDFBOX-4252?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16625161#comment-16625161 ]
Andreas Lehmkühler commented on PDFBOX-4252: -------------------------------------------- I've fixed the first issue as it was an easy one ;-) > PDChoice related bugs and issues > -------------------------------- > > Key: PDFBOX-4252 > URL: https://issues.apache.org/jira/browse/PDFBOX-4252 > Project: PDFBox > Issue Type: Bug > Components: AcroForm > Affects Versions: 2.0.10 > Reporter: Xin Lin > Priority: Major > Labels: Appearance > 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 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 > {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 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.) -- This message was sent by Atlassian JIRA (v7.6.3#76005) --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@pdfbox.apache.org For additional commands, e-mail: dev-h...@pdfbox.apache.org