Here is the code to convert a Word document to PDF.
Note:
- UNTESTED
- Word must be installed
- File may be locked after conversion, so you may need to sleep/process messages
const
wdFormatDocument = 0;
wdFormatDocumentDefault = 16;
wdFormatDOSText = 4;
wdFormatDOSTextLineBreaks = 5;
wdFormatEncodedText = 7;
wdFormatFilteredHTML = 10;
wdFormatFlatXML = 19;
wdFormatFlatXMLMacroEnabled = 20;
wdFormatFlatXMLTemplate = 21;
wdFormatFlatXMLTemplateMacroEnabled = 22;
wdFormatHTML = 8;
wdFormatPDF = 17;
wdFormatRTF = 6;
wdFormatTemplate = 1;
wdFormatText = 2;
wdFormatTextLineBreaks = 3;
wdFormatUnicodeText = 7;
wdFormatWebArchive = 9;
wdFormatXML = 11;
wdFormatXMLDocument = 12;
wdFormatXMLDocumentMacroEnabled = 13;
wdFormatXMLTemplate = 14;
wdFormatXMLTemplateMacroEnabled = 15;
wdFormatXPS = 18;
wdFormatOfficeDocumentTemplate = 23;
wdFormatMediaWiki = 24;
const
wdDoNotSaveChanges = $00000000;
// Convert a DOC or DOCX document to PDF, DOC or DOCX
function ConvertWordToPDF(const InFilename, OutFilename: string: OutFormat: Integer = wdFormatPDF): Boolean;
var
wordApp: OleVariant;
begin
Result := False;
try
wordApp := CreateOleObject('Word.Application');
if VarIsEmpty( wordApp ) then
exit;
wordApp.Visible := False;
wordApp.Documents.Open( InFilename,
false, // ConfirmConversions
true ); // ReadOnly
wordApp.ActiveDocument.SaveAs2( OutFilename, OutFormat );
wordApp.Quit(wdDoNotSaveChanges, EmptyParam, EmptyParam);
wordApp := Unassigned;
Result := True;
except
// Word error
end;
end;
Nigel
Xequte Software
www.imageen.com