//////////////////////////////////////////////////////////////////
// This example was designed for using in Microsoft Visual C++ from
// Microsoft Visual Studio 2003 or above.
//
// 1. Microsoft Visio 2002 or above should be installed and activated on your PC.
//
// 2. Universal Document Converter 5.2 or above should be installed, too.
//
// 3. You must initialize the COM before you call any COM method.
// Please insert "::CoInitialize(0);" in your application initialization
// and "::CoUninitialize();" before closing it.
//
// 4. Import Visio library for 32-bit version of Windows.
// For 64-bit version please change "C:\\Program Files\\" to
// "C:\\Program Files (x86)\\" in all pathes.
#pragma message("Import MS Visio API")
// MS Visio 2002 -> "C:\\Program Files\\Microsoft Office\\Visio10\\Vislib.dll"
// MS Visio 2003 -> "C:\\Program Files\\Microsoft Office\\Visio11\\VISLIB.DLL"
// MS Visio 2007 -> "C:\\Program Files\\Microsoft Office\\OFFICE12\\VISLIB.DLL"#import "C:\\Program Files\\Microsoft Office\\OFFICE12\\VISLIB.DLL"\
rename_namespace("VISIO"), auto_rename
// 5. Import Universal Document Converter software API:#import "progid:udc.apiwrapper" rename_namespace("UDC")
//////////////////////////////////////////////////////////////////void PrintVisioToTIFF( CString sFilePath )
{
// Define constantsconst int visOpenDontList = 0x08, visOpenRW = 0x20, visOpenHidden = 64, visOpenMacrosDisabled = 128;
UDC::IUDCPtr pUDC(__uuidof(UDC::APIWrapper));
UDC::IUDCPrinterPtr itfPrinter = pUDC->Printers["Universal Document Converter"];
UDC::IProfilePtr itfProfile = itfPrinter->Profile;
// Use Universal Document Converter API to change settings of converterd document// Load profile located in folder "%APPDATA%\UDC Profiles".// Value of %APPDATA% variable should be received using Windows API's SHGetSpecialFolderPath function.// Or you can move default profiles into a folder you prefer.
itfProfile->Load("Drawing to TIFF.xml");
itfProfile->OutputLocation->Mode = UDC::LM_PREDEFINED;
itfProfile->OutputLocation->FolderPath = L"C:\\Out";
itfProfile->PostProcessing->Mode = UDC::PP_OPEN_FOLDER;
// Run Microsoft Visio as COM-server
VISIO::IVApplicationPtr objVisioApp( L"Visio.Application" );
VISIO::IVDocumentPtr itfDrawing;
objVisioApp->Visible = false;
// Open drawing from file
itfDrawing = objVisioApp->Documents->OpenEx( (LPCTSTR)sFilePath, visOpenRW | visOpenDontList | visOpenMacrosDisabled | visOpenHidden );
// Change Drawing preferences for scaling it to page
itfDrawing->PrintCenteredH = true;
itfDrawing->PrintCenteredV = true;
itfDrawing->PrintFitOnPages = true;
// Print drawing
itfDrawing->Printer = "Universal Document Converter";
itfDrawing->Print();
// Close drawing
itfDrawing->Saved = true;
itfDrawing->Close();
// Close Microsoft Visio
objVisioApp->Quit();
}