C++操作Word轉pdf

 word轉pdf主要是利用word自帶的函數,主要有三個函數(1)Saveas();(2)PrintOut();(3)ExportAsFixedFormat();這三個

函數可以實現:下面着重對其進行說明:

函數原型public: Void SaveAs( &Object^ FileName, //文件名含路徑名,例如COleVariant(CW2T(_T("G:\\C++\\MFC2table1\\000.pdf"))) &Object^ FileFormat, //    17:wdFormatpdf &Object^ LockComments, //置false;COleVariant((short)false), &Object^ Password,     //置空;COleVariant(_T("")) &Object^ AddToRecentFiles, //置false;COleVariant((short)false), &Object^ WritePassword, //置空;COleVariant(_T("")) &Object^ ReadOnlyRecommended, //置false;COleVariant((short)false), &Object^ EmbedTrueTypeFonts, //置false;COleVariant((short)false), &Object^ SaveNativePictureFormat, //置false;COleVariant((short)false), &Object^ SaveFormsData, //置false;COleVariant((short)false), &Object^ SaveAsAOCELetter, //置false;COleVariant((short)false), &Object^ Encoding, //置false;COleVariant((short)false), &Object^ InsertLineBreaks, //置false;COleVariant((short)false), &Object^ AllowSubstitutions, //置false;COleVariant((short)false), &Object^ LineEnding, //置false;COleVariant((short)false), &Object^ AddBiDiMarks//置false;COleVariant((short)false), );

對於printOut()而言word中必須存在這個選項纔可以執行;而ExportAsFixedFormat()似乎在C++中不能被調用成功,MSDN中C++就沒有該函數,在C#中可以實現

其中主要第二個參數的設置:

NameValueDescription
wdFormatDocument0Microsoft Office Word format.
wdFormatDOSText4Microsoft DOS text format.
wdFormatDOSTextLineBreaks5Microsoft DOS text with line breaks preserved.
wdFormatEncodedText7Encoded text format.
wdFormatFilteredHTML10Filtered HTML format.
wdFormatHTML8Standard HTML format.
wdFormatRTF6Rich text format (RTF).
wdFormatTemplate1Word template format.
wdFormatText2Microsoft Windows text format.
wdFormatTextLineBreaks3Windows text format with line breaks preserved.
wdFormatUnicodeText7Unicode text format.
wdFormatWebArchive9Web archive format.
wdFormatXML11Extensible Markup Language (XML) format.
wdFormatDocument970Microsoft Word 97 document format.
wdFormatDocumentDefault16Word default document file format. For Microsoft Office Word 2007, this is the DOCX format.
wdFormatPDF17PDF format.
wdFormatTemplate971Word 97 template format.
wdFormatXMLDocument12XML document format.
wdFormatXMLDocumentMacroEnabled13XML document format with macros enabled.
wdFormatXMLTemplate14XML template format.
wdFormatXMLTemplateMacroEnabled15XML template format with macros enabled.
wdFormatXPS18XPS format.
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章