Wie füge ich einem (Hyperref-)Textfeld eines PDF-Formulars Zeilenumbrüche hinzu?

Wie füge ich einem (Hyperref-)Textfeld eines PDF-Formulars Zeilenumbrüche hinzu?

Betrachten Sie das folgende Spielzeug-Feedback-Formular:

\documentclass{article}
\usepackage{hyperref}
  \renewcommand*{\DefaultHeightofTextMultiline}{20\baselineskip}

\begin{document}
  \centering
  \begin{Form}
    \TextField[multiline,width=\textwidth,
    value={%
      You should write your feedback in a readable way, for example using bullet points:
      * Insert at least 1 positive comment (mandatory)
      * Insert at least 1 critical comment or question (mandatory)
      \newline
      Use multiple paragraphs.
      \newline
      Some examples of concrete, actionable feedback:
      * The first figure does not have a caption; please add it.
      * The derivation of Equation (7) became unclear around Equation (5). I think this is because you did not make the substitution of x explicit and feel doing so would make the argument clearer.%
  },
  name=mytextfield]{}%
  \end{Form}
\end{document}

Das Kompilieren mit pdflatex ergibt die folgende Warnung (zweimal, eine für jedes \newline):

Package hyperref Warning: Token not allowed in a PDF string (PDFDocEncoding):
(hyperref)                removing `\newline' on input line 20.

Das überrascht mich nicht, da es für die meisten PDF-Felder, die über Hyperref erstellt und ausgefüllt werden, keinen Sinn ergibt, Zeilenumbrüche zu haben, und wahrscheinlich auch nicht unterstützt wird. Wenn ich jedoch das Formular bearbeite und die resultierende Datei speichere (in meinem Fall mit Okular),dürfenZeilenumbrüche hinzufügen. Beim Herausholen der Daten aus dem Formular mitPyPDF2's PdfFileReader.getFields-Methode erhalte ich:

'You should write your feedback in a readable way, for example using bullet points:\n* Insert at least 1 positive comment (mandatory)\n* Insert at least 1 critical comment or question (mandatory)\n\nUse multiple paragraphs.\n\nSome examples of concrete, actionable feedback:\n* The first figure does not have a caption; please add it.\n* The derivation of Equation (7) became unclear around Equation (5). I think this is because you did not make the substitution of x explicit and feel doing so would make the argument clearer.'

Beachten Sie die Zeilenumbrüche \n. Es scheint also möglich zu sein. Ich möchte diese Zeilenumbrüche in meine LaTeX-Datei einfügen. Ist das möglich? Wie kann ich das machen?

\nIch habe naiv versucht, wörtlich als hinzuzufügen \textbackslash{n}, aber das schlägt fehl:

'You should write your feedback in a readable way, for example using bullet points:\\n * Insert at least 1 positive comment (mandatory)\\n * Insert at least 1 critical comment or question (mandatory)\\n \\n Use multiple paragraphs.\\n \\n Some examples of concrete, actionable feedback:\\n * The first figure does not have a caption; please add it.\\n * The derivation of Equation (7) became unclear around Equation (5). I think this is because you did not make the substitution of x explicit and feel doing so would make the argument clearer.'

Antwort1

Aktualisieren: eigentlich ist es besser, \textCRoder zu verwenden \textLF. Sie funktionieren auch, wenn sich die Kodierung ändert.

\string\nfunktioniert bei mir:

\documentclass{article}
\usepackage{hyperref}
  \renewcommand*{\DefaultHeightofTextMultiline}{20\baselineskip}

\begin{document}
  \centering
  \begin{Form}
    \TextField[multiline,width=\textwidth,
    value={%
      You should write your feedback in a readable way, for example using bullet points:\string\n
      * Insert at least 1 positive comment (mandatory)\string\n
      * Insert at least 1 critical comment or question (mandatory)\string\n
      Use multiple paragraphs.
      \string\n
      Some examples of concrete, actionable feedback:\string\n
      * The first figure does not have a caption; please add it.\string\n
      * The derivation of Equation (7) became unclear around Equation (5). I think this is because you did not make the substitution of x explicit and feel doing so would make the argument clearer.\string\n%
  },
  name=mytextfield]{}%
  \end{Form}
\end{document}

Bildbeschreibung hier eingeben

verwandte Informationen