Atozed Forums
Creating and showing PDF - Printable Version

+- Atozed Forums (https://www.atozed.com/forums)
+-- Forum: Atozed Software Products (https://www.atozed.com/forums/forum-1.html)
+--- Forum: IntraWeb (https://www.atozed.com/forums/forum-3.html)
+---- Forum: English (https://www.atozed.com/forums/forum-16.html)
+----- Forum: IntraWeb General Discussion (https://www.atozed.com/forums/forum-4.html)
+----- Thread: Creating and showing PDF (/thread-2764.html)



Creating and showing PDF - David1 - 06-14-2022

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


RE: Creating and showing PDF - DanBarclay - 06-15-2022

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.php?tid=920&pid=2402#pid2402

Note that in post 9 of that thread, Jose has posted a link to sample code.

Dan


RE: Creating and showing PDF - joelcc - 06-16-2022

(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.php?tid=920&pid=2402#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_typeConfusedtring; Send_Stream:boolean=false;AFileNameConfusedtring='';APdfPasswordConfusedtring='');
var lFileName,
lURL,
lFileDirConfusedtring;
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;