Ver Mensaje Individual
  #2  
Antiguo 11-05-2012
gcaffe gcaffe is offline
Miembro
 
Registrado: oct 2004
Posts: 53
Reputación: 20
gcaffe Va por buen camino
NOTA: repito el mensaje anterior porque el código delphi no se ha formateado correctamente

Tengo una aplicación Cliente-Servidor realizada con DataSnap, a la cual quiero agregarle la opción de que el Programa Server, el que se ejecuta remotamente, grabe un fichero PDF en el servidor remoto.
pra la producción de los reportes en el lado Cliente uso la libreria FastReport, y como ella me permite exportar un fichero PDF, haciendo las pruebas he desarrollado el siguiente código:
En el Lado Cliente: Procedimiento que imprime el reporte y los envia al Servidor
Código Delphi [-]
 
procedure TfrmExpediente.btnImpClick(Sender: TObject);
var
Path, Doc: string;
MStream : TMemoryStream;
Arr: TBytes; //Array of Byte;
begin
Path := 'C:\Aplicaciones\Kronos\Reportes\';
with DM do begin
         frxReport.LoadFromFile(Path + 'LstExpedientes.fr3');
         frxReport.PrepareReport();
         frxReport.ShowReport;  // Se imprime el reporte localmente
 // Preparación para la exportación del reporte a PDF
         MStream := TMemoryStream.Create;
         try
            frxReport.SaveToStream(MStream);
            MStream.Position := 0;
  // Puesto que el Stream no es serializable lo convertimos a Array de bytes 
 // y luego a un string para pasarlo como parámetro
            SetLength(Arr, MStream.Size);  
            MStream.Read(Arr[0], MStream.Size);
            Doc := IdGlobal.BytesToString(Arr, nil);
  // Llamo al procedimiento del Servidor a través del DataSnap client class
            with TSMDataDocClient.Create(DM.SQLConnectionDOC.DBXConnection) do begin
               try
                 if not GrabaDocPdf(IntToStr(DM.IDEmpresa),edOficina.Text,edExpediente.Text,1,Doc)
                    then showmessage('No grabado PDF')
                    else showmessage('Correcto');
               finally
                  Free;
               end;
            end;
         finally
            FreeAndNil(MStream);
         end;
end;
end;

En el lado Servidor: Funcion que recibe lo enviado por el cliente y exporta el PDF
Código Delphi [-]
 
function TSMDataDoc.GrabaDocPdf(Cia, Suc, Exp: string; TipoDoc: Integer; Rpt: string): Boolean;
var
PathDOC, FullPath: string;
frxReport: TfrxReport;
frxPDFExport: TfrxPDFExport;
Pdf: TMemoryStream;
begin
Result := False;
// Se crean los componentes frx
frxReport := TfrxReport.Create(Self);
frxPDFExport := TfrxPDFExport.Create(Self) ;
try
      // Convertir el string Rpt a un TMemoryStream
      Pdf := TMemoryStream.Create;
      IdGlobal.WriteStringToStream(Pdf, Rpt, -1);
      try
         Pdf.Position := 0;
         frxReport.LoadFromStream(Pdf);
         frxPDFExport.FileName:= Suc+'-'+Exp+'.pdf';
         frxPDFExport.ShowDialog := False;
         frxPDFExport.ShowProgress := False;
         frxPDFExport.OpenAfterExport := False;
      finally
         Pdf.Free;
      end;
      // Se define la carpeta destino en el Servidor
      FullPath := 'C:\CataDoc\'+ Trim(Cia)+'\'+Trim(Suc)+'\'+ Trim(Exp)+'\';
      if Copy(VerificaPath(FullPath),1,5) <> 'ERROR' then begin
         frxPDFExport.DefaultPath := FullPath;
         Result := frxReport.Export(frxPDFExport); // as frxExportPDF);
      end;
finally
      frxReport.Free;
      frxPDFExport.Free;
end;
end;
// Funcion que verifica si existe la carpeta destino
function TSMDataDoc.VerificaPath(PathDoc: string): string;
var
n: integer;
begin
 while Length(PathDoc) > 0 do begin
      n := Pos('\',PathDoc);
      if n > 0 then begin
         Result := Result+Copy(PathDoc,1,n);
         if not DirectoryExists(Result) then begin
            if not CreateDir(Result) then begin
               Result := 'ERROR '+Result;
               Exit;
            end;
         end;
         PathDoc := Copy(PathDoc,n+1,Length(PathDoc)-n);
      end;
 end;
end;

El problema que se me presenta es el siguiente:
El Servidor recibe el String correctamente, he comprobado que el tamaño del string enviado por el cliente es el mismo que se recibe en el Servidor, sin embargo se graba el PDF vacío, sin contenido.

Por favor alguien me puede indicar como debo realizar esta operación.
Muchas gracias.
Responder Con Cita