Produce a PDF with textbox fields from a markdown document

483 views Asked by At

I have a few hundred LibreOffice documents that I provide to my students as notes. They contain textbox fields that they use to put their answers etc. I would like to merge them into one document so that the chapter/section numbers are updated as I insert, delete, rearrange pages. I would also like to convert them to a markup language such as Markdown or Asciidoc to gain some other advantages for scripting that are unrelated to this question.

Once in this new format I will create PDF documents from individual sections of the master markup document on a regular basis as it is revised. I have done this with a tool such as Asciidoctor PDF and I like it because I can do syntax highlighting in the PDF output.

The part I need some direction with is getting textbox fields in the PDFs. I'm guessing markup languages don't have a tag for this. How about DocBook? Do I need to write some sort of preprocessor for the markup, converting some custom tag that is a stand-in for a textbox on it's way to becoming postscript? I don't know much about PDF or postscript. I'm open to other approaches as I haven't started writing any scripts.

2

There are 2 answers

0
eskwayrd On

In HTML, a textbox is a UI element. In PDF (or on paper), that would just be a "box".

There's no direct Asciidoc markup for making just-a-box, but there is markup that you could use creatively to achieve that goal.

For example, we could use a source block to specify a number of blank lines to define the amount of space that the box should have:

[source, subs="+attributes"]
.Enter your notes here
----
{nbsp}
{nbsp}
{nbsp}
{nbsp}
{nbsp}
----

The {nbsp} entries are using the nbsp attribute, which introduces a non-breaking space. That prevents the source block from collapsing down to a single line. To use {nbsp}, we have to add the subs="+attributes" to the [source] role, or you would see the {nbsp} text itself in the output instead of non-breaking spaces.

You can adjust your asciidoctor-pdf theme to change the background, border, etc. See: https://github.com/asciidoctor/asciidoctor-pdf/blob/master/docs/theming-guide.adoc

If your document already uses source blocks, you might want to use a different kind of block that you are not already using, perhaps an example block, to get the border style that you want. To get the amount of space required, you might use a literal block:

[example]
====
[literal]
....
{nbsp}
{nbsp}
{nbsp}
{nbsp}
{nbsp}
....
====
0
Enrique Motilla On

I'm using FODT format as output from LibreOffice, which is a HTML-Like text format and then using nunjucks on NodeJS to template and fill text and then the final FODT file passed directly to a converter called The Gotenberg project, suitable for office documents. It runs on docker container. You can find it at: https://thecodingmachine.github.io/gotenberg/#introduction

Im using this approach to generate electronic invoices with a very specific format and the final output to a PDF. I liked this approach instead of generating it directly from PDFMake (in nodejs) and others since the template can be modified by anyone in LibreOffice and just save it as FODT (Flat Open Document) and the gotenberg generates a wonderful PDF, and is not using a puppeteer of similar browser engines to generate the PDF.

Regards,