Thursday, January 11, 2018

Generate DOCX to PDF file using Word Automation Service (WAS) in SharePoint using PowerShell


Note: This script will be very useful to test whether the WAS service is working properly in the environment. In addition, it will help to find out the source and destination libraries have proper permissions for the WAS to generate the PDF


clear  
Remove-PSSnapin Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue  
Add-PSSnapin Microsoft.SharePoint.Powershell 

$webAppUrl = "http://webappurl"


[void][System.Reflection.Assembly]::LoadWithPartialName( "Microsoft.Office.Word.Server" ) 

$jobSettings = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJobSettings 

$jobSettings.OutputFormat = "PDF" 

$job = New-Object Microsoft.Office.Word.Server.Conversions.ConversionJob( "Word Automation Services", $jobSettings ) 

$job.UserToken = (Get-SPWeb $webAppUrl).CurrentUser.UserToken 

#Provide the full document url with docx and pdf location

$job.AddFile( "http://webappurl/Shared%20Documents/test1.docx", "http://webappurl/Shared%20Documents/ConvertedDoc.pdf" ) 

$job.Start( )

write-host "Complete"

No comments:

Post a Comment

Access to XMLHttpRequest at 'from origin has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. .net core angular

Issue: The angular application was getting error from API that the origin has been blocked by CORS policy. Solution: Make sure that the...