Universal Document Converter
製品の概要
ダウンロード
ご購入
チュートリアル
開発者の方へ
サポートサービス
fCoder SIAについて


      サイト検索
   


      Video tutorial
Show tutorial



Main page>Developer Solutions>Examples>Visual C++>Word Documents to PDF

Converting Word Documents to PDF


//////////////////////////////////////////////////////////////////
// This example was designed for using in Microsoft Visual C++ from 
// Microsoft Visual Studio 2003 or above.
//
// 1. Microsoft Word 97 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 Office libraries 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 MSO.DLL")
// MS Office 2000 -> "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE10\\MSO.DLL"
// MS Office 2003 -> "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE11\\MSO.DLL"
// MS Office 2007 -> "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE12\\MSO.DLL"
#import "C:\\Program Files\\Common Files\\Microsoft Shared\\OFFICE12\\MSO.DLL" \
	rename_namespace("MSO"), auto_rename
#pragma message("Import VBE6EXT.OLB")
#import "C:\\Program Files\\Common Files\\Microsoft Shared\\VBA\\VBA6\\VBE6EXT.OLB" \
    rename_namespace("VBE6EXT")
#pragma message("Import MS Word API")
// MS Office 2000 -> "C:\\Program Files\\Microsoft Office\\OFFICE\\MSWORD9.OLB"
// MS Office 2003 -> "C:\\Program Files\\Microsoft Office\\OFFICE11\\MSWORD.OLB"
// MS Office 2007 -> "C:\\Program Files\\Microsoft Office\\OFFICE12\\MSWORD.OLB"
#import "C:\\Program Files\\Microsoft Office\\OFFICE12\\MSWORD.OLB" \
	rename_namespace("MSWORD"), auto_rename
// 5. Import Universal Document Converter software API:
#import "progid:udc.apiwrapper" rename_namespace("UDC")
//////////////////////////////////////////////////////////////////
static COleVariant vTrue( (short)TRUE ), vFalse( (short)FALSE ), vOpt( (long)DISP_E_PARAMNOTFOUND, VT_ERROR );
void PrintWordToPDF(CString szFilePath)
{
  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
  itfProfile->PageSetup->ResolutionX = 600;
  itfProfile->PageSetup->ResolutionY = 600;
 
  itfProfile->FileFormat->ActualFormat = UDC::FMT_PDF;
 
  itfProfile->FileFormat->PDF->ColorSpace = UDC::CS_TRUECOLOR;
  itfProfile->FileFormat->PDF->Multipage = UDC::MM_MULTI;
 
  itfProfile->OutputLocation->Mode = UDC::LM_PREDEFINED;
  itfProfile->OutputLocation->FolderPath = L"C:\\Out";
  itfProfile->OutputLocation->FileName = L"&[DocName(0)] -- &[Date(0)] -- &[Time(0)].&[ImageType]";
  itfProfile->OutputLocation->OverwriteExistingFile = FALSE;
  itfProfile->PostProcessing->Mode = UDC::PP_OPEN_FOLDER;
// Run Microsoft Word as COM-server
  MSWORD::_ApplicationPtr itfWordApp(L"Word.Application");
  MSWORD::_DocumentPtr itfWordDoc;
// Open the document from a file
  itfWordDoc = itfWordApp->Documents->Open( COleVariant( szFilePath ) );
  
// Print all pages of the document
  itfWordApp->ActivePrinter = L"Universal Document Converter";
  itfWordApp->PrintOut( vFalse );
// Close the document and Microsoft Word application
  itfWordDoc->Close( vFalse );
  itfWordApp->Quit( vFalse, vFalse, vFalse );
}


© fCoder SIA fCoder SIAについて | サイトマップ