jahlxx Posted February 22, 2018 Share Posted February 22, 2018 Hi. I have created a report, using FR, a everything works fine. Execute the queries, and export to pdf. But this don't work and I don't know how to solve it: UniSession.SendFile(UniServerModule.StartPath + 'files\tmp\' + xreport,xreport); Some help please. Thanks. Link to comment Share on other sites More sharing options...
Volk65 Posted February 22, 2018 Share Posted February 22, 2018 Hi. If I understood you correctly: function TUniReport.ExportReport: Boolean; var Exp1: TfrxPDFExport; Exp2: TfrxJPEGExport; AUrl : string; P: Integer; OldFName, NewFName: String; begin Result:=False; case FExportType of retPDF: begin Exp1:=TfrxPDFExport.Create(nil); try Exp1.Background := True; Exp1.ShowProgress := False; Exp1.ShowDialog := False; -- Get a new file name in the cache !!! Exp1.FileName := UniServerModule.NewCacheFileUrl(False, 'pdf', '', '', AUrl, True); Exp1.DefaultPath := ''; FRF.Export(Exp1); -- Now display this file in a special form to view the PDF frm_UReport_Preview.UniURLFrame1.URL:=AUrl; frm_UReport_Preview.ShowModal; frm_UReport_Preview.Caption:=FRepName; Result:=True; finally Exp1.Free; end; end; If you want to transfer the file to the client instead of displaying it: UniSession.SendFile(Exp1.FileName, SendAsFileName); Link to comment Share on other sites More sharing options...
jahlxx Posted February 22, 2018 Author Share Posted February 22, 2018 no. I have the report, and the pdf generated. all in a separated thread. but unisession sendfile don't work. I don't how to do it when the thread ends. Enviado desde mi SM-A500FU mediante Tapatalk Link to comment Share on other sites More sharing options...
jahlxx Posted February 23, 2018 Author Share Posted February 23, 2018 hi. I've tested with a unitimer. Launch the report in a separated thread, and enable the timer. In the ontimer event, I control if the thread is terminated or not. If yes, disable the timer and sendfile. This work fine, but only in standalone (unitimer is for client side). Now, trying to use unithreadtimer. Launch the report, and do this: unithreadtimer1.enabled := true; And this: if UniThread1.terminated then begin UniSession.SendFile(UniServerModule.StartPath + 'files\tmp\' + xreport2,xreport2); unithreadtimer1.enabled := false; end; This should work, but don't work. Any idea? Thanks. Link to comment Share on other sites More sharing options...
jahlxx Posted February 26, 2018 Author Share Posted February 26, 2018 Hi. I forgot one detail. I use delphi standar class TThread to generate de report (execute queries and export to pdf). My problem is send file to the user once the pdf is finished. I don't know how to do it. Does anyone know how to do? I'm locked with this. Thanks. Link to comment Share on other sites More sharing options...
jahlxx Posted February 26, 2018 Author Share Posted February 26, 2018 OK. I've solved this. With UniTimer. My last test, and works in standalone and isapi is this: procedure TForm1.UniTimer1Timer(Sender: TObject);begin try UniSession.SendFile(UniServerModule.StartPath + 'files\tmp\' + xreport2, xreport2); form1.unitimer1.enabled := false; except form1.unitimer1.enabled := true; end;end; I don't know if is the best solution, but works for me as expected and as I need. If someone has a better solution and/or any suggestion, it will be wellcome. Thanks. Link to comment Share on other sites More sharing options...
Ron Posted February 27, 2018 Share Posted February 27, 2018 The pdf is probably not ready to be sent, so the sendfile fails. Try and do a loop, checking FileExists/sleep if not, and wait to send until it exists, and see if that was the issue. Link to comment Share on other sites More sharing options...
jahlxx Posted February 28, 2018 Author Share Posted February 28, 2018 Ok. With FileExists, allways returns true, because the pdf file exists. Is not ready, but exists while is generated. I do this, and I think is correct: if rpt.Export(exp) then begin assignfile(fic, UniServerModule.StartPath + '\files\tmp\flag.txt'); Rewrite(fic); closefile(fic); end; And in unitimer on time event: if FileExists(UniServerModule.StartPath + '\files\tmp\flag.txt') then begin UniSession.SendFile(UniServerModule.StartPath + 'files\tmp\' + xreport2+'.pdf', xreport2+'.pdf'); flstrendimientos.unitimer1.enabled := false; try deletefile(UniServerModule.StartPath + '\files\tmp\flag.txt'); except end; xreport2 := ''; end; Generate a small txt file, when the export ends. This works for me. Thanks. Link to comment Share on other sites More sharing options...
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now