Thursday, May 12, 2011

Word automation services – Part 1

Common requirement is to convert doc to PDF and for that we often go for the third party software, do the conversion online, in development go for the third party DLL and then call method to do this job.

We now also have an option to convert word document in PDF in office 2010.

Well, now with SharePoint designer 2010 or word automation services, it is possible to convert word document to the PDF file and that too without any watermark.

Word automation service is only available in SharePoint server 2010 not in foundation server.

Word automation service can convert document to one format to another format. You can also do this programmatically as well.

It can read following file formats.
• Word 97-2003 Document (DOC) and Word 97-2003 Template (DOT)
• Rich Text Format (RTF)
• Single File Web Page (MHTML)
• Word 2003 XML
• Word 2007/2010 XML

And it can write following file formats.

• Office Open XML (DOCX, DOCM)
• Word 97-2003 Document (DOC)
• Rich Text Format (RTF)
• Single File Web Page (MHTML)
• Word 2007/2010 XML

So definitely this is a great move from MS and it was highly needed.

Before starting on this, we need to make sure that word automation service is started on the server.

Go to your central administration – Application management – Services on server and see that it is started, if not, then start it.

In this post, I am going to show you how to convert a document to different formats from word and from other formats.

This time we will start with the code. Yes, directly we jump in to the code because it is really easy to convert a document from code for the developers. Just to show you how it works, I am using documents in the same library and outputting the resulting converted documents to the same library.

Output library can also be different from the site. I yet have to check if it works for the site collection or not. But for the site, it definitely works.

You need to include one DLL reference in your project and that is Microsoft.Office.Word.Server.Conversions.ConversionJob.

Once you execute this code, you might have to wait for couple of minutes or more. It depends on the type of file you are converting. Check out different options in conversions.SaveFormat. There are different formats available.

Output from the same above code tried with different formats is shown below.

First is .docx, converted to .doc, .pdf and .xps.

Now one more thing to add here. When you have job object in your hand then you can query its conversion status. As I said earlier, for some file format conversions it might take few minutes.

ConversionJobStatus status = new ConversionJobStatus("Word Automation Services", job.jobId, null);
if (status.Count == status.Succeeded)
// converted

else if (status.Count == status.Failed)
//Not converted. It has failed


Read Part 2 for further reading.


Shafaqat Ali said...


I am trying to find out the dll you have pointed out to add as a reference but i could not, i think this topic is related to SharePoint Server but i have SharePoint Foundation installed.

Just for a suggestion is it possible if you include 1 line comment that this topic is for SharePoint server only?

One more thing, i have done Forms based authentication in SharePoint 2010 using SQL Membership, is it possible if you have a post related to forms based authentication using own custom membership provider? means having own logic to authenticate.

one more :)
I want to have a post related to branding, means having own customized master page, css and images for all sites.

You posts are always helpful, i could not catch all posts for SharePoint 2007 but i am regularly practically implementing all post for SharePoint 2010.

SharePoint Kings said...

ya this article is for Sharepoint Server not Foundation.

actually we only have installed Sharepoint server installed. so all our article will be on Sharepoint Server.

we already article for custom authentication but this one is for sharepoint 2007 so things will be change but you will get idea about custom authentication.

we are more intended to development so we mostly do not have any eureka for designing but still we will try if we got any.


Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to