Bug 157834 - Add simple arithmetic to pdf forms
Summary: Add simple arithmetic to pdf forms
Status: RESOLVED INSUFFICIENTDATA
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: Writer (show other bugs)
Version:
(earliest affected)
7.6.2.1 release
Hardware: All All
: medium enhancement
Assignee: Not Assigned
URL: https://ask.libreoffice.org/t/dynamic...
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-10-20 06:41 UTC by Mike Sapsard
Modified: 2024-06-12 10:37 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments
Files to produce working fillable pdf form. (461.75 KB, application/zip)
2023-10-20 09:43 UTC, Mike Sapsard
Details
Scribus interface for arithmetic (34.25 KB, image/png)
2023-10-20 11:19 UTC, Mike Sapsard
Details
Screenshoots from Scribus showing Javascript insertion for pdf textbox (233.95 KB, application/vnd.oasis.opendocument.text)
2024-06-12 10:25 UTC, Mike Sapsard
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Mike Sapsard 2023-10-20 06:41:24 UTC
Description:
LO Writer produces and exports excellent pdf forms. However, it is not possible to multiply two fields in a row and place the answer in a third field, or to add and subtract fields in a column of cells.

I would like to:
1) multiply two fields in a row. For example: item x quantity -> cost
2) add several fields in a column into a sub total.

Currently, I produce forms in LO, but then use Scribus to add simple arithmetic. Unfortunately, Scribus only does multiplication and adding, before javascript has to be used. If LO could make this capability available, it would be a serious contender for fillable forms. I know from my efforts with Firefox, Chromium, Okular, Foxit and the Document Viewer in Linux Mint that consistent behaviour is a nightmare.

Actual Results:
Add fields to writer document.
Set format of fields - number, integer, real, currency and currency symbol.
Create arithmetic links between them, with output in another field.
Export to pd for fdf.

Expected Results:
Exported form will work in Firefox, Chromium, Okular, Foxit, Acrobat Reader, etc.


Reproducible: Couldn't Reproduce


User Profile Reset: No

Additional Info:
I do not understand. This is a feature request.
Comment 1 Mike Kaganski 2023-10-20 07:19:21 UTC
Can you please provide a Scribus-made form doing simple arithmetics without javascript?
Comment 2 Mike Sapsard 2023-10-20 09:43:23 UTC
Created attachment 190326 [details]
Files to produce working fillable pdf form.

Open zip file, which contains the route to create a working fillable pdf with addition and multiplication. Scribus cannot do subtraction and multiplication, without user generated javascript.

I suspect that there is embedded javascript in the fully working pdf.
Comment 3 Mike Kaganski 2023-10-20 10:01:42 UTC
(In reply to Mike Sapsard from comment #2)

The ODT in your file does not do any arithmetics. So are you asking for "translate to PDF what is already working in ODT", or are you asking for something else?
Comment 4 Mike Sapsard 2023-10-20 11:13:54 UTC
Although LO can do arithmetic in Base and Calc forms, this cannot be exported to pdf for a standalone fillable form.

I would like to be able to create a fillable pdf form with arithmetic, in Write, that can be sent out to other people to fill in.

In the files that I sent, LO exported Demo_Arithmetic.pdf from Demo_Arithmetic.odt.

Scribus then imported Demo_Arithmetic.pdf and translated it to its own format - Demo_Arithmetic.sla. I was then able to add the arithmetic using a simple window with click to select functions to add the arithmetic. The file was then exported again as Demo_Arithmetic_from_Scribus.pdf.

So, the first pdf file contains no arithmetic, and the second one does.
Comment 5 Mike Sapsard 2023-10-20 11:19:02 UTC
Created attachment 190333 [details]
Scribus interface for arithmetic

This is a screenshot of the Scribus interface for adding the capabilty. I believe that it must use javascript underneath.

Unfortunately, it does not allow anything more than addition or multiplication of fields.
Comment 6 Stéphane Guillou (stragu) 2023-11-13 06:56:55 UTC
This has been brought up on ask.LO before:
- https://ask.libreoffice.org/t/dynamic-pdf-fields/96101/4
- https://ask.libreoffice.org/t/math-calculations-in-pdf-forms/12208/4

I understand comment 4 to be the current workaround "recipe" to use a layout created in LibreOffice, export as PDF, open it in Scribus to then add the calculated fields (which uses JavaScript) and export again to PDF.

Adobe Acrobat (Pro and Sign as far as I can tell) also allows creating those too.

So I guess the enhancement request is twofold:
- support calculated fields in a form created with Writer document (is there anything in ODF for that?)
- support their export as PDF

(In reply to Mike Sapsard from comment #4)
> Although LO can do arithmetic in Base and Calc forms, this cannot be
> exported to pdf for a standalone fillable form.
Any chance you could also attach an example Calc file that has such form controls?
Comment 7 Mike Kaganski 2023-11-13 07:20:46 UTC
IMO:

1. There is no built-in means to do calculations in form fields in LibreOffice, other than writing own macros. LibreOffice *must not* put into PDFs anything absent in the source document itself, so any document with simple form fields (but without macros) must never obtain any scripting capability on export - because LibreOffice is not a PDF authoring tool, but its PDF export is designed to just store the document in another format, as is.

2. Even if there is a macro in the document, it is not a LibreOffice task to serve as a AI to convert *programs* from one programming language (say, Basic) and one document model (namely, LibreOffice/UNO document model) into another language (JavaScript) and another document model (PDF API). Not only the two document models are completely different; not only the correct automatic translation of this kind is yet impossible even for most sophisticated AI available currently. It is also a new security risk, which mitigation would be put on TDF.

And then, it would still rely on an implementation of this API in other PDF viewers, giving raise to bugs like "your PDF doesn't calculate in Reader X"...

WONTFIX IMO.

Ref:

https://opensource.adobe.com/dc-acrobat-sdk-docs/acrobatsdk/pdfs/acrobatsdk_jsapiref.pdf
https://helpx.adobe.com/acrobat/using/javascripts-pdfs-security-risk.html
Comment 8 QA Administrators 2024-05-12 03:16:18 UTC Comment hidden (obsolete)
Comment 9 QA Administrators 2024-06-12 03:15:09 UTC Comment hidden (obsolete)
Comment 10 Mike Sapsard 2024-06-12 07:08:58 UTC
This was a feature request, to introduce scripting using JavaScript into pdf forms. I gave examples, that used LO Writer to create the basic form layout and export it to a pdf. The pdf was then imported into Scribus, where Javascript was added to automate addition of various fields. The file was then exported to pdf again, so that a fully functional form existed.

The layout facilities for forms are much better in LO than Scribus for occasional users.

The responses that I received seemed to think that I wanted to pirate and abuse other people's forms, rather than do everything in LO.
Comment 11 Mike Kaganski 2024-06-12 07:58:41 UTC
(In reply to Mike Sapsard from comment #10)
> The responses that I received seemed to think that I wanted to pirate and
> abuse other people's forms, rather than do everything in LO.

No. E.g., my responses were about what I think about this request as (1) requiring LibreOffice to implement a translation of arbitrary programs from one scripting language and one object model to another language and model, which is currently not possible even for advanced AI; and (2) introducing a security risk. Your phrase here looks very odd.
Comment 12 Mike Sapsard 2024-06-12 10:25:36 UTC
Created attachment 194678 [details]
Screenshoots from Scribus showing Javascript insertion for pdf textbox
Comment 13 Mike Sapsard 2024-06-12 10:37:17 UTC
I obviously was not clear, and apologise.

I was looking for a method to add JavaScript to pdf exports from LO. Currently, I create forms in LO and then export to pdf. To add the JavaScript, I open the pdf file in Scribus and add the JavaScript. Scribus has two forms of textbox - 'ordinary' and 'pdf'. The pdf textboxes have a component editor that allows formatting of basic functions - sum, product, etc, without coding. Results can be checked in FireFox and Chromium.

Some of the Scribus screens are shown in the third attachment above.

The only problem may be that the ODT spec does not allow embedding of the additional functionality in the source file.

Mike Sapsard