This blog is moved to
http://amalhashim.wordpress.com

Monday, May 2, 2011

SharePoint 2010 Word Automation Services

Professional SharePoint 2010 AdministrationaltBeginning SharePoint 2010 Development (Wrox Beginning Guides)Microsoft SharePoint 2010: Building Solutions for SharePoint 2010 (Books for Professionals by Professionals)altMicrosoft® SharePoint® 2010 Administrator's Companionalt

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://<your site URL>/"+ filex.Url, "http://<your site URL>/"+ 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”

1 comment:

Unknown said...

It throws an error


The name 'ConfigurationHelper' does not exist in the current context