.NET Convert Word Document into PDF


I came across this old code of converting Word into PDF:

This used to work well until recently the avdoc object sometimes doesn't get the instance (i.e. null) , however running it twice usually fixed it.

I don't know what caused this. It might be a system update or something. I also researched that the above code shouldn't even work since it's using Acrobat interop to open a 'doc' type - so that code was kind of a hack.

To fix the issue, I decided to find alternative way of converting word to PDF pro grammatically. This other way requires office 12 interop instead. So the idea is to open the doc in office and save it as PDF. Simple enough! here is the code:

P.S: Don't forget to install Office2007 and Acrobat on the machine :) enjoy!

Post a Comment