How to enable PDF forms in the Conversion API?

Hello

I’m trying to convert an ODT to a PDF with editable form fields using the Conversion API.

To generate the ODT in desktop LibreOffice you can just place a form text box (View > Toolbars > Form controls) and then invoke export to PDF (File > Export As > Export as PDF…) making sure to enable the “Create PDF form” checkbox in the export dialog.

Moreover, in a desktop command-line scenario you can use the --convert-to option, which generates the editable PDF form correctly, without the need for any options:

libreoffice --convert-to pdf --outdir . test_form.odt

But Coolwsd’s Conversion API generates a PDF without form fields.

So I dug into LibreOffice’s source code and I found the relevant property in the PDF export filter, it’s called “ExportFormFields” and it appears to be set by default to true (same file, line 106.)

I tried setting the option explicitly to true using the options parameter, which if I understand correctly, should be a JSON:

curl -sS http://127.0.0.1:9980/cool/convert-to/pdf -F data=@test_form.odt -F options='{"ExportFormFields":true}' -o test_form.pdf

and I verified in the logs it is being passed to LOK:

kit-27722-27720 2023-03-23 16:28:16.687113 +0000 [ kitbroker_001 ] DBG ToMaster-001: Calling LOK's saveAs with URL: [], Format: [pdf], Filter Options: [{"ExportFormFields":true}]| kit/ChildSession.cpp:2542

but the converted PDF still has no form fields.

I checked in the Python UNO documentation, which also lists the ExportFormFields option as defaulting to true.

At this point I’m lost. Does anybody have any idea where this option is getting lost? Why does it work with UNO and the commandline --convert-to, but not with the Conversion API?

Hello @tobia please have you find a solution for this ? I’m facing same issue. i’m using “code” in docker to convert odt files to pdf but forms are not created. It’s work fine with jod localconverter which use locally installed libreoffice. I need to use it in android so the conversion needs to be done remotely.

No, sorry, I haven’t found a solution. I wanted to look at OnlyOffice next.

Could you please confirm this still happens with CODE 24.04?

I just tried the following:

  1. create a(n ODT) document with a checkbox content control
  2. convert to PDF using the convert-to API:
curl -k -F "data=@test.odt" -F "format=pdf" https://localhost:9980/cool/convert-to > test.pdf

and I got a fillable PDF form, i.e. the setting you mention was enabled by default.

Perhaps you’re on an older version or something? Thanks.

1 Like