SharePoint

Synchronous document conversion with Word automation

WordAutomation2013

In a previous post I explained about Word Automation Services in SharePoint 2010. It worked and the converted files were of a good quality. However there was still some space for improvements. I’ll show what changed in SharePoint 13 in the Word Automation Services.

Drawbacks in SharePoint 2010

  • Solutions must wait until timer job executes for file generation
  • Can only handle files in SharePoint
  • No easy way to know when conversion has been completed

Word Automation in SharePoint 2013

  • New Immediate based request (no waiting)
    • New option to execute conversion immediately, not necessarily from timer job
    • Operate on one file at the time per request
    • Configuration options from CA for simultaneous request amount
  • Notify or update items in SharePoint after completion
    • Word Automation Services can perform file conversions and can update files
  • Allow WAS to support streams
    • Convert streams from API perspective as inputs and outputs for file operations
    • Streams are stored in memory within Application Server Manager and Worker – not in content database

Architecture

WordAutomationArchitectureSharePoint13

Object model

The object model has a new class, SyncConverter. The Convert method brings new capabilities. With the ConvertJob there was only the possibility to convert files that were in SharePoint. This new method offers the option to convert streams and byte array’s besides the already existing url.

Create an on demand file conversion

public static byte[] WriteSpFile(SPFile spFile)
{
   using (Stream read = spFile.OpenBinaryStream())
   {
       using (MemoryStream write = new MemoryStream())
       {
           string wordAutomationServiceName = "Word Automation Services";
           SyncConverter sc = new SyncConverter(wordAutomationServiceName);
           SPSite spSite = SPContext.Current.Site;
           sc.UserToken = spSite.UserToken;
           sc.Settings.UpdateFields = true;
           sc.Settings.OutputFormat = SaveFormat.PDF;

           ConversionItemInfo info = sc.Convert(read, write);
           if (info.Succeeded)
           {
               return write.ToArray();
           }
       }
   }
   return null;
}

The code snippet above shows a synchronous document conversion with streams. The code inside the using statement is the real conversion. There’s no direct option to convert a url to a stream. I think this should be added in the next version.

Share this

3 thoughts on “Synchronous document conversion with Word automation

  1. Hi.

    Tried to follow this and build a farm based solution on our test SP machine. However after referencing the Microsoft.Office.TranslationServices.dll – see article at http://msdn.microsoft.com/en-us/library/microsoft.office.conversionservices.conversions.syncconverter.aspx) – that I found in a folder in the GAC I’m getting an error that I cannot create an instance of the abstract class …SyncConverter. Am I using the right dll? Can you help?

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *