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!

[sourcecode language=”csharp”]

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()

[/sourcecode]

Disable the sandbox mode:

[sourcecode language=”csharp”]

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

[/sourcecode]

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.

About Karsten Schneider 312 Articles
Consultant for Microsoft 365 Applications with a strong focus in Teams, SharePoint Online, OneDrive for Business as well as PowerPlatform with PowerApps, Flow and PowerBI. I provide Workshops for Governance & Security in Office 365 and Development of Solutions in the area of Collaboration and Teamwork based on Microsoft 365 and Azure Cloud Solutions. In his free time he tries to collect tipps and worthy experience in this blog.

8 Comments

  1. 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

    • 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

  2. Karsten

    sorry I didn’t see an alert on the your last reply.

    There is codeplex by Scott Hillier ( CriticalPath) sample out that wraps the WAS in a Restful Service . Comes with a handy App Action. I deployed both the app and service. It has a bug that seems to be related to spaces in the filename but I will look at that tomorrow. It is not quick so on our dev server it took 3-5 mins on a 440K doc as supplied by my client . Be interested on hearing your thoughts.

    As you say I will be calling the conversion service from a Sp2013 workflow …

    Sorry to keep adding comments…..
    regards
    Daniel

  3. Hi Mr. Karsten,

    Sorry to keep adding comments. I just need your help regarding conversion. Is it possible to use powershell in converting InfoPath form to PDF file through sharepoint?

    Thanks!

2 Trackbacks / Pingbacks

  1. SharePoint, Office365 & Yammer Nuggets of weeks 16,17 & 18 - Ragnar Heil: SharePoint Nuggets - Site Home - MSDN Blogs
  2. SharePoint, Office365 & Yammer Nuggets of weeks 16,17 & 18

Leave a Reply to Nancy anderson Cancel reply

Your email address will not be published.


*