While developing, I had encountered a problem. Main idea of code is using MS Word to convert .doc and .rtf to .pdf files format. Code is working perfectly for exe-application. But using this code in a service application causes a problem: calling ExportAsFixedFormat method raises an exception "Invalid variant operation". I'd running out of ideas, how to fix this. Do anybody has one?
function DocToPDFByWord (sFileName,sPDFFileName :string;) : byte;
  const
    wdExportFormatPDF = 17;
    wdDoNotSaveChanges = 0;
  var
    vOLEApp ,vDocument : OleVariant;
begin
  Result := 0;
  CoInitialize (nil);
  vOLEApp := CreateOLEObject ('Word.Application');
  if VarIsNull(vOLEApp) then
    begin
      Result := 1;
      Exit;
    end;
  vOLEApp.Visible:= False;
  try
    vDocument := vOLEApp.Documents.Open(FileName:= sFileName, ConfirmConversions:= False, ReadOnly:= True, AddToRecentFiles:= False, PasswordDocument:= 'dummy', PasswordTemplate:= 'dummy', Revert:= True, Visible:= False, OpenAndRepair:= False, NoEncodingDialog:= True);
    if VarIsNull(vDocument) then
      Result := 2
    else
      try
        vDocument.ExportAsFixedFormat (sPDFFileName ,wdExportFormatPDF);
      except
        Result := 3;
      end;
  except
    Result:= 4;
  end;
  vOLEApp.Quit (wdDoNotSaveChanges);
  vOLEApp := Unassigned;
  CoUnInitialize;
end;