Converting Microsoft Outlook Messages to TIFF for Visual Basic.NET
'----------------------------------------------------------------------
' 1) Microsoft Outlook 2000 or above should be installed and activated on your PC.
'
' 2) Universal Document Converter 5.2 or above should be installed, too.
'
' 3) Open your project in Microsoft Visual Basic.NET.
'
' 4) In Visual Basic main menu press "Project->Add Reference...".
'
' 5) In "Add Reference" window go to "COM" tab and double click into
' "Universal Document Converter Type Library".
'----------------------------------------------------------------------
Private Shared readyFlag As Boolean = False
Private Shared myTimer As New System.Windows.Forms.Timer()
Private Shared Sub TimerEventProcessor(ByVal myObject As Object, ByVal myEventArgs As EventArgs)
' This is the method to run when the timer is raised.
myTimer.Stop()
readyFlag = True
End SubPrivate Sub WaitSomeTime(ByVal nSec As Single)
AddHandler myTimer.Tick, AddressOf TimerEventProcessor
myTimer.Interval = nSec * 1000
myTimer.Start()
While readyFlag = False
' Processes all the events in the queue.
Application.DoEvents()
End WhileEnd SubPrivate Sub PrintOutlookMsgToTIFF(ByVal strFilePath As String)
Const olDiscard = 1 ' = Outlook.OlInspectorClose.olDiscardDim objUDC As UDC.IUDC
Dim itfPrinter As UDC.IUDCPrinter
Dim itfProfile As UDC.IProfile
Dim objOutlook As Object
Dim itfMsg As Object
objUDC = New UDC.APIWrapper
itfPrinter = objUDC.Printers("Universal Document Converter")
itfProfile = itfPrinter.Profile
' Set Universal Document Converter as default printer, because
' Outlook's API interface allow printing only on default printer
objUDC.DefaultPrinter = "Universal Document Converter"
' Use Universal Document Converter API to change settings of converterd document
itfProfile.FileFormat.ActualFormat = UDC.FormatID.FMT_TIFF
itfProfile.FileFormat.TIFF.ColorSpace = UDC.ColorSpaceID.CS_BLACKWHITE
itfProfile.FileFormat.TIFF.Compression = UDC.CompressionID.CMP_CCITTGR4
itfProfile.OutputLocation.Mode = UDC.LocationModeID.LM_PREDEFINED
itfProfile.OutputLocation.FolderPath = "C:\Out"
itfProfile.PostProcessing.Mode = UDC.PostProcessingModeID.PP_OPEN_FOLDER
' Open MS Outlook as COM-server
objOutlook = CreateObject("Outlook.Application")
' Open Outlook MSG file
itfMsg = objOutlook.CreateItemFromTemplate(strFilePath)
' And print it on the default printerCall itfMsg.PrintOut()
' Close opened file
itfMsg.Close(olDiscard)
' Wait until Outlook finished printing process
WaitSomeTime(5)
' Close Outlook applicationCall objOutlook.Quit()
objOutlook = Nothing
End Sub