Preface
I’m working on a project where I need to digitize the form filling process for a testing lab company. The company currently fills out forms manually and makes 40 copies of each form. The form itself is obscenely large (138 pages, 300+ input fields). The forms are then given to a tester who jots down his observations. All of the results are combined back into a result form which is then digitized, printed, and sent to the government. It is imperative that the format is preserved.
The form name is IEC 62368-1 (I have attached an Image as I could not find a web downloadable version). There is a Data sheet and a Test Report by the lab, but all of this process needs to be digitized. I want to create a system where the forms can be filled out digitally, and the data from these forms is used to populate a Word document template. This Word document is then saved and can be printed or sent digitally.
Here’s an example of the data sheet:
62368-1 Test Data Sheet
And here’s an example of the corresponding report sheet:
I want to create a system where a user can fill out a form (either an HTML form or a Microsoft Form), and the data from this form is used to populate a Word document template. The Word document should maintain the same formatting as the original document. The placeholders in the Word document should be added by the program.
Additional Challeges and Preferences
The form needs to be in printable condition which raises the following issues:
Handling images when stitching back the document
- these fields need to be resized in order to fit the image size on paper
Microsoft Stack is Preferred as the company deals in Microsoft Products. ( PowerApps, Azure OpenAI/ Document Intelligence)
The solution I have in mind is that I generate 2 templates each (Test Report and Data Sheet) which is filled by a form (Microsoft Form or a custom Form) and then using Microsoft Automate/Flows this data is sent into an azure function which aggregates all data sheet observations from multiple testers and does some processing and enters into the test report. The Test Report template would resize itself according to the input from the processed Azure Function (Image Fields would expand to the size and images can shrink to fit). Because of the template the layout would be preserved, and Azure functions can take care of the size fields. User will only need to upload Blank Data Sheets and Test Reports, which will be stored on their SharePoint with the processed files that I discussed above. The Manager would be notified when the processed files are available for download.
What I've Tried
I’ve tried using docxtemplater to create and populate the Word document, but I’m having trouble adding the placeholders to the Word document. I’m also not sure how to maintain the formatting of the original document.
I have also tried Microsoft Forms into Word, but Forms has a character limit which this easily crosses (200 questions per form).
I tried the Word Developer tab -> Microsoft Word Forms but then I would need to label 300 questions across 40 forms which is not at all possible
The One thing that works almost perfectly is Adobe Forms and automatic labelling. It needs some input from the user, but it does most of it, which is the kind of result I am expecting but as its closed source I cannot resize Image input fields with custom JavaScript (which adobe can run)
Is there a way to do this using JavaScript or any AI service? Any help would be greatly appreciated!
Since you mention python, you can achieve this with python using docx-mailmerge
but first, you need made a docx as your template and adding MERGEFIELD Mail Merge, Open your docx template.
Note: field name must be identical with the variable name that you assign of. In my example, you need to add report_number and date_of_issue for the field name.
or you can follow the instructions from this link Populating MS Word Templates with Python
Adding image can also be done using python-docx. combine docx-mailmerge and python-docx can be useful.