Developing a custom Word Export Tool
TOC markerWhy?
No sane person would ever attempt to work with word on a code-level, right? It is closed-source and developed by Microsoft, right? And yet I still made a tool for it?
One day a relative of mine approached me with a problem. He had alot of word files that needed converting to pdf, a few hundred at least. Doing all of that by hand takes to long, so another solution was needed.
TOC markerPrinting PDFs
My first attempt (after looking through Stack Overflow) was to simply print all documents as PDF via Microsofts tools. This has (historically) a few problems. Firstly, this utilises the Print Spooler and Queue. These are notorically buggy pieces of code which work in mysterious ways against the user. Secondly, an user input is needed to specify the export filename. I tried tapping straight into the converter and still could not get it running just right with it sometimes just ignoring paths. To add insult to injury, the converter sometimes was just wrong. WortArt e.g. just did not convert properly.
TOC markerMacros
At some point I was seriously just considering using a macro or AHK-script to do all the work, which would have honestly worked fine. Then I remembered Microsoft Apps are basically just GUIs for Powershell nowadays, so I researched into how e.g. Teams or Outlook can directly launch other Microsoft services. As it turns out, there is an .NET API for word documented here. This API is intended for Word Plugins and interaction with the system. Luckily, this operates on the DOS-level of Windows, so everyone with a somewhat recent word can simply interact with it in e.g. Powershell. Powershell is a great tool if utilized correctly and can do almost anything Bash will do for you under Linux. Like with .sh-scripts, there are .ps1-scripts for Powershell. Someone might just start an instance of word and tell the program to open, export and close documents while looping through a list of filepaths. My solution just consists of a Powershell script reading in filepaths and then telling word to export them to a fixed path with fixed formatting. This is a bulletproof way to get what you see in word as a PDF and works for basically infintely many files.
TOC markerFurther reading
In the end a solution by my cousin was used. He created a full-fledged C#-program basically doing the same thing, but with a GUI, "because Windows users need that". My script follows quite opposite design principles. It is however still available at this location with a German documentation page detailing how to use it. If you have any questions regarding mass conversion/export of Word to PDF or the script feel free to shoot me an E-Mail.