1
Answer

Command line word to PDF converter

Bryan Head

Bryan Head

17y
1.6k
1
I am trying to write a program that converts a word document to pdf from the command line. This seemingly simple task, however, has turned out to be quite difficult. So far, I have written a program that interacts with the Office object library. It creates a new instance of Word and loads the .doc into it and then prints it to PrimoPDF (or CutePDF Writer). It then closes word, etc.

The problem with this is that both print drivers I have tried require the user to input the output file name in a little window they throw up when the print command is given. The whole point of the program is to automate the process (it is going to be part of a build sequence), so requiring any user input except at the command line is evil. But, if you know of any print drivers that require no such user input, that would work perfectly. Or, if you know a way to simulate keyboard input, that would work too.

I'm sure there are many other ways to accomplish this. I don't have the Acrobat SDK and even if I did, I'm not sure how I would get it to play nicely with the Word files. I also don't have the libraries Aspose made. Anybody know anything open source that can interact with Word docs and pdf docs? I spose I could parse the Word files for all their information (maybe the Word object will do this nicely) and then write the pdf file line by line. Unfortunately, it seems that text is encrypted in PDFs, so this would require cracking that... Um, unless somebody knows how to do this, this is not an option.

Any ideas? Thanks in advance!

PS - I'm pretty new to C#, though I think I'm picking it up pretty fast. Anyway, please be a little gentle :)

Oh! Also, if you know a good, free program that already does this, that would be good too! Surprisingly, I couldn't find anything that really worked well.
Answers (1)