PDFExport open in new Window: a solution !

Hi All,

I've managed to get the PDF Export to open the PDF file in a separate window. I works as a SA application when running the program in the IDE, when running the program from disk AND, when running it as a service installed on a server. I have not tested, but suppose it will work as an ISAPI under IIS as well.

What I do is:

Create a filename with an URL pointing to the Users Document folder. This could be any folder and even a shared folder on a server somewhere. Conditions is that the user running the program, have R/W access to the folder. For multi user environments, running the application as a Service on a server, I suggest to use some kind of unique filename.

Call the TIWAdvWebGridPDF1.Export with this name as param 1 and "False" as param 3, forcing TIWAdvWebGridPDF1.Export not to show the PDF but to create a file.

Add the file to the Temp Filecache with the AddToFileCache function, giving an URL to that file.

Call Webapplication.NewWindows with the temp URL as param

and finally: Delete the original file to clean up. Temp filecache will be cleaned up by the browser, depending on Settings.

All done in the OnClick of a Button:

procedure TIWForm1.Button1Click(Sender: TObject);
var PDFFilename : string;
      PDFURL: string;
  PDFFilename := GetEnvironmentVariable('USERPROFILE') +'\Documents\TempPDF.pdf';
  TIWAdvWebGridPDF1.AdvWebGrid := TIWAdvWebGrid1;
  if not fileexists(PDFFilename) then exit;
  PDFURL := TIWAppCache.AddFileToCache(Self, PDFFilename, TIWMimeTypes.GetAsString(mtPDF), ctOneTime);
  if fileexists(PDFFilename) then deletefile(PDFFilename);

Remember to put the following units in the Uses list for the form. I've added them to the Uses in the implemention section:

uses   IW.Common.SysTools,

One problem solved :-)


Thanks for your suggestion and example!