Making SharePoint 2010 and Word Automation Services convert to pdf immediately.For Real.
As a result I was stuck with two options:
Give something (ApplicationPool, Site, WCF Service) farm admin permissions to run a timerjob
Use some characteristic of my website or sitecollection to indicate word conversion should be executed and have some other code (another timerjob, eventreceiver) execute the runnow method.
The first is not really an option for any production environment of course. I couldn’t sleep calmly knowing something with this high level of permissions is publicly available. Let alone that our administrators would have probably punched me out of the building the moment I would have asked them.
The second option will work just fine. I just could not live with the sheer complexity of this kind of solution. For immediate synchronous conversion I would have to deploy a TimerJob that runs every minute and checks on some flag I set on my website. This means the worst case conversion will take place 1 minute + original word service timer job runtime from now. Unacceptable for me.
Ok after my little rant, I calmed down a little. My final solution was to reverse engineer the conversion process and use internal private API through reflection to do the conversion(It was built by man, it can be controlled by man! :-D). This of course will probably not be compatible with newer versions of SharePoint but what do you know, SharePoint 2013 does all that out-of-the-box. But what can I tell you, it works just fine. This method is of course not ideal either. But it works, and it is totally reliable. It does not circumvent load balancing or any other mechanisms. Just make sure you don’t call it hundreds of times every minute :-) Depending on your environment you’ll have to adapt it because remember: With great power comes the necessity to think twice about your SharePoint solution.
Enough talk, here’s the code:
And because I am a big fan of writing tests, I started writing an Nunit test for running it. It is not completed but nevertheless I wanted to include it here so it doesn't feel sad. *currently working on that test*