Einzelnen Beitrag anzeigen

Benutzerbild von erich.wanker
erich.wanker

Registriert seit: 31. Jan 2008
Ort: im schönen Salzburger Land
454 Beiträge
 
Delphi XE4 Professional
 
#1

ISAP -> DOC to PDF -> CreateOleObject('Word.Application') funktioniert nicht

  Alt 18. Apr 2024, 13:45
Hallo,
meine ISAP Anwendung (um ein bestehendes Word-DOC in ein PDF umzuwandeln) funktioniert nicht.
Ich vermute - es hängt damit zusammen dass die ISAPI vom Apache mit "Loakes System" ausgeführt wird?
Wenn ja - wie kann ich ein "CreateOleObject As Admin" oder so ähnlich ausführen? -- oder irgedwie anders ein Word-Doc in ein PDF konverteiren?
Den Apach Dienst am Server darf ich nicht als anderen User ausführen

Danke für Hinweise
Erich

Hier mein Code:

Uses Comobj, Varianst
Vars: WordAllication und WordFile : OLEVariant;

Code:
          WordApplication := Null;
          WordFile := Null;

          try
            // create Word OLE
            try
              // Check if Word is already opened?
              WordApplication := GetActiveOleObject('Word.Application' );
            except
              try
                WordApplication := CreateOleObject('Word.Application' );
                WordApplication.Visible := true;
              except
                Exception.Create( 'Error' );
              end;
            end;

          except
            WordApplication := Null;
          end;

          If VarIsNull( WordApplication ) = False
          then
          begin
            try
              WordApplication.Visible := true; // set to False if you do not want to see the activity in the background
              WordApplication.DisplayAlerts := true; // ensures message dialogs do not interrupt the flow of your automation process. May be helpful to set to True during testing and debugging.

              // Open Word File
              try
                WordFile := WordApplication.Documents.Open(merge_dateiname_mit_pfad );
              except
                WordFile := Null;
              end;

              If VarIsNull( WordFile ) = False
              then
              begin
                WordFile.SaveAs2( merge_destfolder + '\aenderung' + UniMainModule.Z_AENDERUNG.FieldByName( 'Reportnummer' ).AsString + '\converted.pdf', 17 ); // wdFormatPDF = 17
              end
              else
              begin
                showtoast('Word-Dokument konnte nicht konvertiert werden');
              end;
            finally
              WordFile.Close;
              WordApplication.DisplayAlerts := true;
              WordApplication.Quit;
              WordFile := Unassigned;
              WordApplication := Unassigned;
            end;
          end
          else
          begin
            showtoast('Word konnte nicht gestartet werden');
          end;
Erich Wanker - for life:=1971 to lebensende do begin ..
O
/H\
/ \
  Mit Zitat antworten Zitat