|
<< Click to Display Table of Contents >> Navigation: Forum > Creating and showing PDF |
06-14-2022, 03:39 PM:
Hello,
I am using IW 15.2.57 and Delphi 11.1.
I would like to show a dinamically created pdf after a user select an invoice in a TIWjQDBGrid.
To create the pdf I am using the export feature of Fast-Report reporting tool.
I am using the following code:
Code:
var AppPath: string := WebApplication.ApplicationPath;
var CacheFileName: string := TIWAppCache.NewTempFileName();
QryDeliveries.Close;
QryOrder.Close;
QryOrder.ParamByName('OrderNo').AsString := FSelectedOrderNo;
QryOrder.Open;
QryDeliveries.Open();
Report.EngineOptions.EnableThreadSafe := True;
Report.EngineOptions.DestroyForms := False;
Report.LoadFromFile(Format('%sreports\Spedizioni.fr3', [AppPath]));
try
Report.PrepareReport;
PDFExport.FileName := CacheFileName;
Report.Export(PDFExport);
finally
Report.Clear;
end;
var Url: string := TIWAppCache.AddFileToCache(GGetWebApplicationThreadVar(), CacheFileName, 'application/pdf', ctOneTime);
WebApplication.NewWindow(Url);
At the beginning selecting different invoice the pdf is correctly shown but after some selection the pdf report the same invoice without correctly update the invoice data basing on the selected invoice.
What I am doing wrong?
Thank you,
Davide
06-15-2022, 02:49 AM:
I don't use Fast Report, but I have followed conversations here regarding threading issues with that lib. It is not intended for multi threading like a web server. The solution is to use the CGIRunner component and place the report code in a single thread project.
Check here:
https://www.atozed.com/forums/showthread...02#pid2402
Note that in post 9 of that thread, Jose has posted a link to sample code.
Dan
06-16-2022, 02:23 PM:
(06-15-2022, 02:49 AM)DanBarclay Wrote: [ -> ]I don't use Fast Report, but I have followed conversations here regarding threading issues with that lib. It is not intended for multi threading like a web server. The solution is to use the CGIRunner component and place the report code in a single thread project.
Check here:
https://www.atozed.com/forums/showthread...02#pid2402
Note that in post 9 of that thread, Jose has posted a link to sample code.
Dan
There is no threading issues with fastreport if you set all of these settings.
// this code is very important and needs to be called right after the report is created.
lFrxReport.EngineOptions.EnableThreadSafe := True;
lFrxReport.EngineOptions.UseGlobalDataSetList := False;
lFrxReport.ReportOptions.Compressed := True;
lFrxReport.EngineOptions.SilentMode := True;
lFrxReport.EngineOptions.DestroyForms := False;
lFrxReport.EngineOptions.UseFileCache := False;
lFrxReport.ShowProgress := False;
Here is also a procedure for using ReportBuilder if anyone needs it.
procedure fxProcess_Report(ARBreport:TppReport;Output_typetring; Send_Stream:boolean=false;AFileNametring='';APdfPasswordtring='');
var lFileName,
lURL,
lFileDirtring;
lMS : TMemoryStream;
lPDFDevice: TppPDFDevice;
begin
try
with ARBreport do
begin
AllowPrintToFile := False;
ShowPrintDialog := False;
TextFileName := lFileDir;
DeviceType := 'PDF';
ModalCancelDialog := false;
ModalPreview := false;
ShowCancelDialog := false;
lMS := TMemoryStream.Create;
lPDFDevice := TppPDFDevice.Create(nil);
try
lPDFDevice.PDFSettings := ARBreport.PDFSettings;
lPDFDevice.OutPutSTream := lMS;
lPDFDevice.Publisher := ARBreport.publisher;
ARBreport.PrintToDevices;
lURL := IWappCache.TIWAppCache.StreamToCacheFile(WebApplication, lMS, TIWMimeTypes.GetAsString('.' + 'PDF'), ctSession);
WebApplication.NewWindow( lURL
, 'Report'
, 0
, 0
, [woResizable, woDetectBlock]
);
finally
lPDFDevice.free;
lMS.free;
end;
end;
except
raise;
end;
end;