PowerShell
It looks like you can do it with Powershell on the commandline pretty easily.
Open a QProcess
, and run:
http://technet.microsoft.com/en-us/library/hh847736.aspx
powershell -Command "Import-Module MSOnline";"C:\Myscript.ps1"
(Download this script or convert it to C++ com calls.)
https://gallery.technet.microsoft.com/office/Script-to-convert-Word-f702844d
powershell -Command "Import-Module ConvertWordPocumentToPDF.psm1";"ConvertTo-OSCPDF -Path C:\path\to\document.docx"
So the end code for Qt probably could be something like:
QProcess * process = new QProcess();
// put code to pipe stdout and stderr from the QProcess to this exe's stdout, or to a TextEdit.
process->start("powershell.exe -Command \"Import-Module ConvertWordPocumentToPDF.psm1\";\"ConvertTo-OSCPDF -Path C:\\path\\to\\document.docx\"");
Com Object Access
DocumentBase.ExportAsFixedFormat Method
http://msdn.microsoft.com/en-us/library/microsoft.office.tools.word.documentbase.exportasfixedformat.aspx
public void ExportAsFixedFormat(
string outputFileName,
WdExportFormat exportFormat,
bool openAfterExport,
WdExportOptimizeFor optimizeFor,
WdExportRange range,
int from,
int to,
WdExportItem item,
bool includeDocProps,
bool keepIRM,
WdExportCreateBookmarks createBookmarks,
bool docStructureTags,
bool bitmapMissingFonts,
bool useISO19005_1,
ref Object fixedFormatExtClassPtr
)
First get an instance of a Word.Application
then get an instance of a document using wdApplication.Documents.Open
then call wdDocument.ExportAsFixedFormat
, with the parameters of:
$wdExportFormat = [Microsoft.Office.Interop.Word.WdExportFormat]::wdExportFormatPDF
$OpenAfterExport = $false
$wdExportOptimizeFor = [Microsoft.Office.Interop.Word.WdExportOptimizeFor]::wdExportOptimizeForOnScreen
$wdExportItem = [Microsoft.Office.Interop.Word.WdExportItem]::wdExportDocumentContent
$IncludeDocProps = $true
$KeepIRM = $true
$wdExportCreateBookmarks = [Microsoft.Office.Interop.Word.WdExportCreateBookmarks]::wdExportCreateWordBookmarks
$DocStructureTags = $true
$BitmapMissingFonts = $true
$UseISO19005_1 = $false
$wdStartPage = 0
$wdEndPage = 0
(but formatted for c++, not powershell)
then when it is completed, release the com objects.
http://msdn.microsoft.com/en-us/library/kw65a0we.aspx
I haven't tested either method, but I have ran Com objects from a Qt project before. Hope that helps.