资源简介
word转pdf源码,可以实现word文档转为pdf文档
代码片段和文件信息
#include “StdAfx.h“
#include “Converter.h“
CConverter::CConverter(void)
{
}
CConverter::~CConverter(void)
{
}
//
// Word转换成PDF
//
//
//
BOOL CConverter::Convert(CString strSourcePath CString strTargetPath MSWord::WdExportFormat wdExportFormat)
{
BOOL result = FALSE;
MSWord::_ApplicationPtr pWdApplicationPtr;
MSWord::_DocumentPtr pWdDocumentPtr;
COleVariant sourcePath = strSourcePath;
COleVariant targetPath = strTargetPath;
COleVariant vTrue((short)TRUE);
COleVariant vFalse((short)FALSE);
COleVariant vZero((short)0);
COleVariant vOptional((long)DISP_E_PARAMNOTFOUND VT_ERROR);
CoInitialize(NULL);
try
{
HRESULT hResult = pWdApplicationPtr.CreateInstance(“Word.Application“);
if (hResult != S_OK)
{
AfxMessageBox(_T(“Application创建失败,请确保安装了word 2000或以上版本!“) MB_OK|MB_ICONWARNING);
CoUninitialize();
return result;
}
pWdDocumentPtr = pWdApplicationPtr->Documents->Open(sourcePath
vTrue // Confirm Conversion.
vFalse // ReadOnly.
vFalse // AddToRecentFiles.
vOptional // PasswordDocument.
vOptional // PasswordTemplate.
vOptional // Revert.
vOptional // WritePasswordDocument.
vOptional // WritePasswordTemplate.
vOptional // Format. // Last argument for Word 97
vOptional // Encoding // New for Word 2000/2002
vFalse // visible
vOptional // openAndRepair
vZero // docDirection
vOptional // NoEncodingDialog
vOptional);
//pWdDocumentPtr = pWdApplicationPtr->Documents->Open2000(sourcePath
// vTrue // Confirm Conversion.
// vFalse // ReadOnly.
// vFalse // AddToRecentFiles.
// vOptional // PasswordDocument.
// vOptional // PasswordTemplate.
// vOptional // Revert.
// vOptional // WritePasswordDocument.
// vOptional // WritePasswordTemplate.
// vOptional // Format. // Last argument for Word 97
// vOptional // Encoding // New for Word 2000/2002
// vOptional); // Visible
if(pWdDocumentPtr == NULL)
{
CoUninitialize();
return result;
}
hResult = pWdDocumentPtr->ExportAsFixedFormat((_bstr_t )strTargetPath // target path
wdExportFormat // export format
FALSE // Open After Export
wdExportOptimizeForPrint // Export OptimizeFor
wdExportAllDocument // Export Range
0 // start page
0 // end page
wdExportDocumentContent // Export Item
TRUE // Include Doc Props
TRUE // Keep IRM
wdExportCreateWordBookmarks // Export Create Bookmarks
TRUE // Doc Structure Tags
TRUE // Bitmap Missing Fonts
FALSE); // Use ISO19005_1
if (hResult == S_OK)
{
result = TRUE;
}
}
catch(CException* e)
{
TCHAR szError[1024];
e
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 93686 2011-03-24 10:26 Source\office文档转PDF工具.docx
文件 545077 2011-03-24 10:27 Source\SaveAsPDFandXPSOffice转PDF.rar
文件 80698 2011-04-02 10:40 WordToPdf\Include\Excel\CApplicationExcel.h
文件 46320 2011-04-02 10:13 WordToPdf\Include\Excel\CWorkbookExcel.h
文件 8154 2011-04-02 10:13 WordToPdf\Include\Excel\CWorkbooksExcel.h
文件 14326 2011-04-02 13:35 WordToPdf\Include\Ppt\CApplicationPpt.h
文件 24320 2011-04-02 13:35 WordToPdf\Include\Ppt\CPresentationPpt.h
文件 3641 2011-04-02 13:34 WordToPdf\Include\Ppt\CPresentationsPpt.h
文件 47222 2011-04-02 13:02 WordToPdf\Include\Word\CApplicationWord.h
文件 76809 2011-04-02 10:10 WordToPdf\Include\Word\CDocument0Word.h
文件 8055 2011-04-02 10:08 WordToPdf\Include\Word\CDocumentsWord.h
文件 59904 2011-04-02 14:53 WordToPdf\Release\WordToPdf.exe
文件 5524480 2011-04-02 14:53 WordToPdf\Release\WordToPdf.pdb
文件 7085 2011-04-02 14:53 WordToPdf\WordToPdf\Converter.cpp
文件 1672 2011-04-02 14:52 WordToPdf\WordToPdf\Converter.h
文件 2799 2011-03-29 11:00 WordToPdf\WordToPdf\ReadMe.txt
文件 6712 2011-04-02 14:53 WordToPdf\WordToPdf\Release\BuildLog.htm
文件 616808 2011-04-02 14:53 WordToPdf\WordToPdf\Release\Converter.obj
文件 5032834 2010-03-13 14:53 WordToPdf\WordToPdf\Release\excel.tlh
文件 4851312 2010-03-13 14:53 WordToPdf\WordToPdf\Release\excel.tli
文件 1191903 2010-10-08 21:10 WordToPdf\WordToPdf\Release\mso.tlh
文件 914595 2010-10-08 21:10 WordToPdf\WordToPdf\Release\mso.tli
文件 1168817 2010-03-08 19:23 WordToPdf\WordToPdf\Release\msppt.tlh
文件 957912 2010-03-08 19:23 WordToPdf\WordToPdf\Release\msppt.tli
文件 2757205 2010-03-26 21:52 WordToPdf\WordToPdf\Release\msword.tlh
文件 2223213 2010-03-26 21:52 WordToPdf\WordToPdf\Release\msword.tli
文件 65 2011-04-02 14:53 WordToPdf\WordToPdf\Release\mt.dep
文件 2558713 2011-04-02 14:17 WordToPdf\WordToPdf\Release\stdafx.obj
文件 66636 2010-02-25 11:07 WordToPdf\WordToPdf\Release\vbe6ext.tlh
文件 56350 2010-02-25 11:07 WordToPdf\WordToPdf\Release\vbe6ext.tli
............此处省略36个文件信息
评论
共有 条评论