////////////////////////////////////////////////////////////////////////////////////////////////////// This example was designed for using in Microsoft Visual C# from // Microsoft Visual Studio 2003 or above.//// 1. Microsoft Outlook 2000 or above should be installed and activated on your PC.// Microsoft Outlook Express does not have COM interface and cannot be used as COM-server!//// 2. Universal Document Converter 5.2 or above should be installed, too.//// 3. Add references to "Microsoft Outlook XX.0 Object Library" and "Universal Document Converter Type Library"// using the Project | Add Reference menu > COM tab.// XX is the Microsoft Office version installed on your computer.////////////////////////////////////////////////////////////////////////////////////////////////////using System;
using System.IO;
using UDC;
using Outlook = Microsoft.Office.Interop.Outlook;
namespace OutlookToTIFF
{
classProgram
{
staticvoid OutlookToTIFF(string OutputTemplateFilePath)
{
//Create a UDC object and get its interfacesIUDC objUDC = newAPIWrapper();
IUDCPrinter Printer = objUDC.get_Printers("Universal Document Converter");
IProfile Profile = Printer.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
Profile.FileFormat.ActualFormat = FormatID.FMT_TIFF;
Profile.FileFormat.TIFF.ColorSpace = ColorSpaceID.CS_BLACKWHITE;
Profile.FileFormat.TIFF.Compression = CompressionID.CMP_CCITTGR4;
Profile.OutputLocation.Mode = LocationModeID.LM_PREDEFINED;
Profile.OutputLocation.FolderPath = @"C:\UDC Output Files";
Profile.PostProcessing.Mode = PostProcessingModeID.PP_OPEN_FOLDER;
//Run Microsoft Outlook as COM-server
Outlook.Application OutlookApp = new Outlook.ApplicationClass();
Object Missing = Type.Missing; //This will be passed when ever we don’t want to pass value//Open document from file
Outlook.MailItem MailItem = (Outlook.MailItem)OutlookApp.CreateItemFromTemplate(OutputTemplateFilePath, Missing);
//And print it on the default printer
MailItem.PrintOut();
//Close opened file
MailItem.Close(Outlook.OlInspectorClose.olDiscard);
//Wait until Outlook finished printing process
System.Threading.Thread.Sleep(5000);
//Close Outlook application
OutlookApp.Quit();
}
staticvoid Main(string[] args)
{
string TemplateFilePath = @"c:\Docs\Test.msg";
OutlookToTIFF(TemplateFilePath);
}
}
}