I’ve got a tough one, and hoping someone here can help me out?
I have an existing .DOCX file that is “protected”. I need to add text and embed (as OLE icons) up to 3 files. I then need to convert it to a .DOC file as the output. The kicker? I need to do this all programmatically. My preference would be to do this in Linux, but I’d be willing to use Windows if absolutely necessary. This script will need to repeat this action over 100 times each day, so using a GUI is not an option.
I have a very awkward means of doing this in Windows (Server 2012), but it relies on .VBS and use of COM objects, which are becoming more & more restricted & difficult to use with each security update. It involves:
1. Unzipping the .DOCX & converting to text.
2. Adding the attachment filenames to the manifest
3. Altering the XML to remove the protection
4. Re-zipping back to a .DOCX file with VBS
5. Opening the modified .DOCX with a COM object
6. Using a complex PHP script to select an icon & add the OLE object
7. Adding the text
8. Saving the file as .DOC
What I’m hoping to find is a way to do steps 1-7 in LibreOffice via a pre-defined script. I know how to do it via the GUI, but that is not an option in my particular situation. Steps 1-4 are basically just removing the protection, while steps 5-7 do the actual embedding into the .DOCX.
I already know how to use unoconv to convert to .DOC, so I can handle that bit. (Step 8) I’ll attach some examples to illustrate more of what I mean:
Does anybody here know how to use something like the “unoconv” function or “soffice --headless” to embed OLE objects & text? And if there is also a way to remove the protection in a headless manner, I’d be thrilled to get rid of .VBS too.