Code Samples - Neevia docCreator

Example 2: Convert a MS Word document into PDF - Delphi Copy 

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
   procedure convertWordToPDF();
   var
     RVal : Integer;

     DC,
     MSWord,
     NewDoc,
     MSWordDialog : Variant;

     tempFile,
     docToConvert : String;
   begin
      docToConvert := 'c:\users\public\test.doc';

      try
        DC := CreateOleObject('Neevia.docCreator');

        DC.setParameter('DocumentOutputFormat', 'PDF');
        DC.setParameter('DocumentOutputName', 'testDOC_Delphi');
        DC.setParameter('DocumentOutputFolder', 'c:\users\public\');

        tempFile := DC.getParameter('TempDir') + DC.GUID + '.ps';

        try
          MSWord := CreateOleObject('Word.Application');
          MSWord.DisplayAlerts:= False;
          NewDoc := MSWord.Documents.Open(docToConvert, false, true);

          MSWordDialog := MSWord.Dialogs.Item(97);
          MSWordDialog.Printer := 'Neevia docCreator';
          MSWordDialog.DoNotSetAsSysDefault := 1;
          MSWordDialog.Execute;

          NewDoc.PrintOut(false,emptyparam,emptyparam,tempFile,
                          emptyparam,emptyparam,emptyparam,
                          emptyparam,emptyparam,emptyparam,true);

          NewDoc.Close(False);
          MSWord.Quit(False);

          DC.setInputDocument(tempFile);
          RVal := DC.create; // Create output document
          if (RVal <> 0) then
            ShowMessage('Error while creating document!!! Code: '+IntToStr(RVal))
          else
            ShowMessage('Document Created !!!');
        except
          on E: Exception do
            ShowMessage(E.Message);
        end
      finally
        DC := Unassigned;
        MSWord := Unassigned;
      end;  
   end;