First, import a library like "Microsoft Word 12 Objects" (MS Word 2007) into your project using the components | Import components. Then you can use this sample code to download the MS Word file and save it as a PDF using an internal PDF converter. If you are using Microsoft Word 2010, download its type library instead of Word 2007.
unit fMain; interface uses Windows, SysUtils, Variants, Classes, Controls, Forms, Dialogs, StdCtrls, Word_TLB; type TfrmMain = class(TForm) btnLoad: TButton; btnSaveAs: TButton; FileOpenDialog1: TFileOpenDialog; FileSaveDialog1: TFileSaveDialog; procedure btnLoadClick(Sender: TObject); procedure FormClose(Sender: TObject; var Action: TCloseAction); procedure btnSaveAsClick(Sender: TObject); private FWordApp : WordApplication; FWordDoc : WordDocument; procedure InitializeApp; procedure FinalizeApp; function LoadFile(const AFileName: string): WordDocument; procedure SaveAsPdf(ADocument: WordDocument; const AFileName: string); public { Public declarations } end; var frmMain: TfrmMain; implementation uses ComObj; {$R *.dfm} procedure TfrmMain.btnLoadClick(Sender: TObject); begin if FileOpenDialog1.Execute then FWordDoc := LoadFile(FileOpenDialog1.FileName); end; procedure TfrmMain.btnSaveAsClick(Sender: TObject); begin if FileSaveDialog1.Execute then begin if Assigned(FWordDoc) then SaveAsPdf(FWordDoc, FileSaveDialog1.FileName); end; end; procedure TfrmMain.FinalizeApp; var SaveChanges: OleVariant; begin if Assigned(FWordApp) then begin SaveChanges := False; FWordApp.Quit(SaveChanges, EmptyParam, EmptyParam); FWordApp := nil; end; end; procedure TfrmMain.FormClose(Sender: TObject; var Action: TCloseAction); begin FinalizeApp; end; procedure TfrmMain.InitializeApp; begin FWordApp := createOleObject('Word.Application') as WordApplication; if Assigned(FWordApp) then begin FWordApp.Visible := False; end else raise Exception.Create('Cannot initialize Word application'); end; function TfrmMain.LoadFile(const AFileName: string): WordDocument; var FileName: OleVariant; Doc : WordDocument; begin if not Assigned(FWordApp) then InitializeApp; FileName := AFileName; Doc := FWordApp.Documents.Open(FileName, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam); Result := Doc; end; procedure TfrmMain.SaveAsPdf(ADocument: WordDocument; const AFileName: string); var FileName, FileFormat : OleVariant; begin if Assigned(ADocument) then begin FileName := AFileName; FileFormat := wdFormatPDF; ADocument.SaveAs(FileName, FileFormat, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam); end; end; end.
I just wrote the code and ran it once, it works, but I did not test it completely, so there may be some glitches.