Share via


SharePoint 2013: Using Word Automation Services to convert a Word Document into PDF

Case

An error as described below during the docx to pdf conversion using Word Automation Service Application in SharePoint 2013.

Code

#Add-PSSnapin Microsoft.SharePoint.PowerShell# Input parameters for the script#$listUrl="Approved Agreement Forms"$listUrl="All Agreement Forms under process"# 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 "https://myserver/sites/mysite"# Set the credentials to use when running the conversion job.$conversionJob.UserToken = $web.CurrentUser.UserToken# Conversion Job Name$conversionJob.Name = "ConvertDOCXtoPDF1"$conversionJob.Settings.OutputFormat = [Microsoft.Office.Word.Server.Conversions.SaveFormat]::PDF$conversionJob.Settings.UpdateFields = $true$conversionJob.Settings.OutputSaveBehavior = [Microsoft.Office.Word.Server.Conversions.SaveBehavior]::AlwaysOverwrite#Get list$list = $web.Lists[$listUrl]foreach ($itm in $list.Items){for ($i =0; $i >=2; $i++) {    if($itm.File.Name.ToLower().EndsWith(".docx") -eq $true) {        Write-Host $($itm.File.ServerRelativeUrl)        $conversionJob.AddFile($($web.Site.MakeFullUrl($itm.File.ServerRelativeUrl)), $($web.Site.MakeFullUrl($itm.File.ServerRelativeUrl).ToLower().Replace(".docx", ".pdf")))            }    }}# Start the conversion job$conversionJob.Start()

Error in PowerShell

Exception calling "Start" with "0" argument(s): "The service application required to complete this request is not currently available. Try this operation again later. If the problem persists, contact your administrator."

At D:\Migration\Document Conversion.ps1:34 char:1

+ $conversionJob.Start()

+ ~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException

    + FullyQualifiedErrorId : SPException

 

When you look at the ULS logs , it is not at generating the logs due to memory was hitting 100% when it finds some memory found below clue in ULS.

Error in ULS

Error: Enable ULS and   Filter the ULS logs with  Product is equal to Word Automation Services.

Proxy 'DWProd Word Automation Services': Exception connecting to service application: System.ServiceModel.ServiceActivationException: The requested service, 'http://myserver:32843/fc23852d4cbc4511b3be479864b55de3/Service.svc' could not be activated. See the server's diagnostic trace logs for more information. 

When you browse  this URL 'http://myserver:32843/fc23852d4cbc4511b3be479864b55de3/Service.svc: Server is having less than 5% of memory , try after some time. Forgot to take snap shot.

Solution

Release the server from hitting 100% memory and rerun the code by limiting the number of PDF conversion to lesser number in our case it is set to 25.