I haven't been able to find a solution yet.
Only solutions using Powershell please. How can a Word *.docx file be converted to a PDF *.pdf file please without using a COM object. This is to run on a virtual server via a Windows Task Schedule with 'run even if user is NOT logged on' option ticked which is why the current COM object solution is not working (if I untick this option it works but not suitable option).
I found a PSWriteWord powershell module to do the search and replace portion of the code (word template to new word file) but it does not appear to support save as PDF. There is also a PSWritePDF module but again it does not appear to have this functionality.
$filePath = "C:\Temp6"
$origFile = "$filePath\Template.docx"
$newFile = "$filePath\ReplacedText.docx"
# Get the original document
$WordDocument = Get-WordDocument -FilePath $origFile
# Search and replace some text
ForEach ($Paragraph in $WordDocument.Paragraphs) {
$Paragraph.ReplaceText('[given_name]','Jane')
$Paragraph.ReplaceText('[surname]','Doe')
}
# Save as new document
Save-WordDocument -WordDocument $WordDocument -FilePath $newFile
# Quick check to confirm Word application is not left open
Get-Process -name WinWord -ErrorAction SilentlyContinue
# How to convert/save as PDF WITHOUT COM Object?
Thank you.