PdfBox-Android icon indicating copy to clipboard operation
PdfBox-Android copied to clipboard

Question: PDTextField value with line break "\n"

Open SkyGanfor opened this issue 4 years ago • 1 comments

Hi, I've been generating PDFs using user input and some of the text input allows for line breaks that span multiple lines. I set these strings using PDTextField.setValue() and a typical multiline string would look like this: "This is a test string\nThis is a new line\nAnd another"

Problem is, after setting a string with line breaks and generating the PDF, this causes the lines to combine and overlap one another rather than separating to a separate line below (see pic). Does anyone know of a way to set strings with line breaks and have them reflect in a PDF text field?

Screen Shot 2020-10-02 at 12 46 29 PM (The entire "Notes" box is a text field and its multiline has been set to true)

Here the full code of how I set the value:

PDField treeNode;
try {
      treeNode = acroForm.getField(textFieldName);
      if (treeNode instanceof PDTextField) {
          PDTextField textField = ((PDTextField) treeNode)
          textField.setMultiline(true);
          textField.setValue(text);
      } else {
          throw new IOException();
      }
} catch (IOException ignored) {
}

SkyGanfor avatar Oct 02 '20 16:10 SkyGanfor

hi guys, any news about that one? we have the same issue here and tried a few workarounds with no luck.

regards from sunny Vienna -Eduard

eram1979 avatar Jul 12 '21 15:07 eram1979