# How to create an editable field in a pdf using python latex?

I'm looking forward how to insert editable empty fields in the final pdf. In TexStudio I got this simple example of using forms: Multi-line Comment Boxes in Interactive PDFs with LaTeX

\documentclass[10pt]{article}

\usepackage{hyperref}

\begin{document}
\begin{Form}
\noindent
\TextField[name=multilinetextbox, multiline=true,  width=\linewidth,height=1in]{}
\end{Form}
\end{document}


I need to create multiples reports using processing data in python and exporting to latex, so I try PyLatex, but I didn't found something like this. Any help?

• Welcome to TeX.SX! – Skillmon Sep 11 '17 at 13:25
• It is not clear to me what the data generation in Python has got to do with the creation of fillable forms. Do you want to prefill the forms with the Python output, but keep them editable in the final PDF? – Michael Palmer Sep 11 '17 at 13:41
• Are you just asking how to generate code like that with pylatex? – Torbjørn T. Sep 11 '17 at 14:44
• @MichaelPalmer I will input multiple graphs and figures in latex directly from my python model (this I could do). But, in the report, I'll have a field to write (by typing) some informations. Because that, I try to ask a question here, hoping to get some advice about to do this inside Pylatex. – Isaque Daniel Sep 11 '17 at 15:46
• Never hurts to mention that you asked the same thing somewhere else as well (github.com/JelteF/PyLaTeX/issues/192). I should say, that I'm not entirely sure that everyone here would consider this question on topic, as it's really a purely Python question. (After all, you know which LaTeX code you want.) I did post an answer anyway though. – Torbjørn T. Sep 11 '17 at 16:19

With some inspiration from examples in the pylatex repo, in particular environment_ex.py. The Python code

import pylatex as pl

class Form(pl.base_classes.Environment):
"""A class to wrap hyperref's form environment."""

_latex_name = 'Form'

packages = [pl.Package('hyperref')]
escape = False
content_separator = "\n"

doc = pl.Document()

with doc.create(Form()):
doc.append(pl.Command('noindent'))
doc.append(pl.Command('TextField',
options=["name=multilinetextbox", "multiline=true",
pl.NoEscape("width=\linewidth"),"height=1in"],
arguments=''))

doc.generate_tex('demo')


generates

\documentclass{article}%
\usepackage[T1]{fontenc}%
\usepackage[utf8]{inputenc}%
\usepackage{lmodern}%
\usepackage{textcomp}%
\usepackage{lastpage}%
\usepackage{hyperref}%
%
%
%
\begin{document}%
\normalsize%
\begin{Form}
\noindent
\TextField[name=multilinetextbox,multiline=true,width=\linewidth,height=1in]{}
\end{Form}%
\end{document}
`