Friday, May 20, 2011

Introduction Word Automation Services in SharePoint 2010

Word Automation Services is a big part of that pillar, and represents our desire to ensure that the power and functionality of Word is available beyond the desktop; in this case, by enabling developers to harness the capabilities of Word on the server as part of SharePoint 2010.

What is Word Automation Services in SharePoint Server 2010?

Ever tried to transfer .docx files into PDF? Most of us try to perform server side conversions of Open XML files (.docx) into fixed formats (PDF and XPS) using the Word desktop application. Isn’t it? Now this conversion can be done hassle-free with Word Automation Services.

As an element of SharePoint 2010, Word Automation Services allows you to perform file operations on the server that previously required automating desktop Word:

* Converting between documents formats (e.g. DOC to DOCX)

* Converting to fixed formats (e.g. PDF or XPS)

* Updating fields

* Importing “alternate format chunks”

Features of Word Automation Services

Features of Word Automation Services include the following:

Reliability – Word Automation Service was built from the ground up to work in a server environment, which means that you no longer have to worry about issues like dialog boxes that bring the process to a halt, expecting a user to provide input; creating interactive user accounts under which to run the application to avoid running into permissions issues, etc.

Speed – The service is optimized to perform server-side file operations, and in doing so provides performance significantly better than existing solutions.

Scalability – The service can take advantage of the processing power available on typical server hardware (multiple processors, additional memory). For example, although a single instance of WINWORD.EXE can only utilize a single core of processing power, with Word Automation Services, you can specify the number of simultaneous conversions (and the # of processing cores) to use based on the available hardware.

What Word Automation Service doesn’t do?

One of the most important things to understand about Word Automation service is what it doesn’t do. Word Automation Service is not intended to be a 1:1 replacement for the existing desktop object model. Instead, the server is one half of a replacement for the existing object model – the other half being the Open XML SDK.

  • The SDK is designed to handle tasks that don’t require application logic, such as inserting or deleting content (paragraphs, tables, pictures), inserting data from other data sources, sanitizing content (removing content, accepting tracked changes), etc.
  • The service is designed to handle those few tasks that do need application logic: reading all of the document formats that Word supports, converting to all of the output format that Word supports, recalculating dynamic fields, etc.
In SharePoint 2010, you can add "Word Automation Services" from Central Admin as shown below

image

Once the service is in place, we can easily convert Word documents to PDF as shown in below snippet

private voidConvertDocFileToPDF(SPFile filex)
{
ConversionJobSettings settings = newConversionJobSettings();
settings.OutputFormat = SaveFormat.PDF;
ConversionJob job = newConversionJob(ConfigurationHelper.Instance.DocumentConversionService, settings);
job.UserToken = SPUserToken.SystemAccount;
stringpdfFile = filex.Url.Replace("docx", "pdf");
job.AddFile("http:///"+ filex.Url, "http:///"+ pdfFile);
job.Start();
}

Ensure to add reference to “Microsoft.Office.Word.Server” present under 14 hive “ISAPI” folder.

To test this, run “Word Automation Services Timer Job”

No comments: