Quantcast
Channel: Windows PowerShell forum
Viewing all articles
Browse latest Browse all 21975

How to automate Print to PDF

$
0
0

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.

functionConvertTo-PDF {
	param(
		$TextDocumentPath)Add-Type-AssemblyNameSystem.Drawing
	$doc =New-ObjectSystem.Drawing.Printing.PrintDocument
	$doc.DocumentName= $TextDocumentPath
	$doc.PrinterSettings=new-ObjectSystem.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.



Viewing all articles
Browse latest Browse all 21975

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>