Hi
I have a folder with n number of outlook message files with extension ".msg". The content of these files should be converted to PDF without altering its format using Microsoft Print to PDF option and the
output files should be saved to a folder with .pdf extension automatically.
Any help on this?
Note: I have already tried using below script and it prints only blank pages in PDF.
function ConvertTo-PDF {
param(
$TextDocumentPath
)
Add-Type -AssemblyName System.Drawing
$doc = New-Object System.Drawing.Printing.PrintDocument
$doc.DocumentName = $TextDocumentPath
$doc.PrinterSettings = new-Object System.Drawing.Printing.PrinterSettings
$doc.PrinterSettings.PrinterName = 'Microsoft Print to PDF'
$doc.PrinterSettings.PrintToFile = $true
$file=[io.fileinfo]$TextDocumentPath
$pdf= [io.path]::Combine($file.DirectoryName, $file.BaseName) + '.pdf'
$doc.PrinterSettings.PrintFileName = $pdf
$doc.Print()
$doc.Dispose()
}
Thanks.