..:: I like SharePoint ::.. Rotating Header Image

What you should know about Word Automation Services in SharePoint to convert word to pdf

In multiple customer projects we had the requirement to convert word documents to pdf. There are really many ways to achieve this by using third party tools, OpenXML SDK and pdf rendering software or any other kind. SharePoint offers a so called Word Automation Service which can also transform your word document into pdf file. But this feature is only available at SharePoint Server Standard or higher. So 3rd party tools are great if you only use SharePoint Foundation.

In this post i assume that you have SharePoint Server Standard and i will write about the possibilities you have with the Word Automation Services (WAS). Let’s see what the input and output could be.

Source files types:

  • Open XML File Format documents (.docx, .docm, .dotx, .dotm).
  • Word 97-2003 documents (.doc, .dot).
  • Rich Text Format files (.rtf).
  • Single File Web Pages (.mht, .mhtml).
  • Word 2003 XML Documents (.xml).
  • Word XML Document (.xml)

Destination file types:

The supported destination document formats includes all of the supported source document formats, and the following.

  • Portable Document Format (.pdf)
  • Open XML Paper Specification (.xps)

In order to use it, you have to configure the word automation services as service application in SharePoint and it should be started. You can do it in the central administration in manage service applications. If you want to know the details of how it works i can recommend you to read this post. Here are also listed the limitations of WAS.

The big bang is, that there is no UI. What does it mean? Well, if you think that there is a button or context menu at each document or a feature which has to be activated now, you’re wrong. It is now possible to use it, but how?There are several options which i will list:

  • Developing your own custom action to start a conversion or use solutions from codeplex Solution 1 | Solution 2 | Solution 3
  • Developing your own custom activity to use it in a SharePoint Designer Workflow or in Visual Studio Workflow
  • Developing a custom Timer Job which starts the conversion
  • Developing an event receiver which starts the conversion
  • Using Powershell Script and put it into a windows task if it has to be converted at special times

As you can see, you have to develop or script something. I post my Powershell Script here. It starts the conversion. BUT it will not work in sandboxed mode.That’s why i also have a second script which will disable the sandbox mode for the WAS. It is also important if you develop it in code. The solution has to be a farm solution not sandboxed!



Add-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue
# Input parameters for the script
$wordFile="http://server/sites/SiteCollection/Document/WordDocument.docx"
$date = Get-Date -format yyyy_MM
$pdfFile="http://server/sites/SiteCollection/Document/WordDocument"+$date+".pdf"
# Get the Word Automation Service Proxy
$wasp = Get-SPServiceApplicationProxy | where { $_.TypeName -eq "Word Automation Services Proxy" }
#Create the Conversion job
$conversionJob = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJob($wasp)
# Get the web url
$web = Get-SPWeb "http://server/sites/TenneT/Ohu"
# Set the credentials to use when running the conversion job.
$conversionJob.UserToken = $web.CurrentUser.UserToken
# Conversion Job Name
$conversionJob.Name = "Convert docx to PDF"
$conversionJob.Settings.OutputFormat = [Microsoft.Office.Word.Server.Conversions.SaveFormat]::PDF
$conversionJob.AddFile($wordFile,$pdfFile)
# Start the conversion job
$conversionJob.Start()


Disable the sandbox mode:



$sp = Get-SPServiceApplication | where {$_.TypeName.Equals("Word Automation Services")}
$sp.DisableSandbox = $true
$sp.Update()


Afterwords make an iisreset.

You should know that the conversion is an asynchronous process. So remember this if you develop a user interface and remember it also if you start the conversion and refresh the page! It may take up to 15min. cause the timer job “Word Automation Services Timer Job” runs every 15min. If you start it manually it will start the conversion.

Okay, what are the main things from this post?

  • Converting documents to pdf
  • NO UI – you have to code it
  • NO UI – you cannot start it easily by clicking a button
  • Many possibilities
  • NOT in SP Foundation

Happy Converting!

The article or information provided here represents completely my own personal view & thought. It is recommended to test the content or scripts of the site in the lab, before making use in the production environment & use it completely at your own risk. The articles, scripts, suggestions or tricks published on the site are provided AS-IS with no warranties or guarantees and confers no rights.

Karsten Pohnke About Karsten Pohnke
He is Consultant for SharePoint Solutions for collaboration, communication and business processes. He provides his customers applications based on standard features as well as development or combining the power of several microsoft tools like Dynamics CRM. In his free time he tries to collect tipps and worthy experience in this blog.

4 Comments

  1. […] Automation Services in SP2013An introduction to this service which can e.g. convert word documents into pdfs […]

  2. […] Automation Services in SP2013An introduction to this service which can e.g. convert word documents into pdfs […]

  3. Daniel says:

    Karsten

    A very neat solution. I have the some requirement. I would prefer to link my conversion to a declarative SharePoint 2013 workflow so that I can covert on Publish major. Any thoughts on this please?

    Daniel

    1. Hi Daniel,
      you could write a Custom SharePoint Designer Workflow Activity which handles the conversion. We did this already for a customer project. Or even use it for SharePoint 2013 Workflow, i guess there you can write a custom activity, too.
      Hope it helps you?
      Karsten

Leave a Reply

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


four × nine =

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>