There is a code that loads the necessary scripts (html2canvas.js, FileSaver.js, canvastoBlob.js) onto the site, creates a canvas and saves it accordingly, but displays a standard save file dialog.

The file name is always the same, that is, you need to overwrite the file.

procedure TMainForm.Button2Click(Sender: TObject); begin //подключаем 3 скрипта для сохранения картинки. loadHtml2Canvas; //выполняем скрипт crm.Browser.MainFrame.ExecuteJavaScript( 'setTimeout(function(){'+ 'var body = jQuery("iframe").contents().find("body");'+ //создаем канву ' html2canvas(body, {'+ ' onrendered: function(canvas) {'+ ' canvas.toBlob(function(blob) {'+ //Cохраняем ' saveAs(blob, "file.jpeg");'+ ' }, "image/jpeg");'+ ' }'+ //end onrendered '});'+//end html2canvas '}, 900);',//end setTimeout crm.Browser.MainFrame.Url, 0); end; 

How can I catch | bypass the file saving window caused by TChromium saving the file just to the root with the program? Perhaps there is an event in the TChromium itself before saving the files or is it easier?

Solution (after 20 minutes): in TChromium there is an OnBeforeDownload event in it we call the Cont function where we pass the path and the second parameter is our dialog window = False, the window will not be = the file is saved.

 procedure TMainForm.crmBeforeDownload(Sender: TObject; const browser: ICefBrowser; const downloadItem: ICefDownloadItem; const suggestedName: ustring; const callback: ICefBeforeDownloadCallback); begin callback.Cont(ExtractFilePath(ParamStr(0)) + suggestedName, False); end; 
  • Post the solution with the answer and mark it as correct with a daw - Kromster
  • Ok, I write that I can make a decision only in two days :) - TheGrizli

1 answer 1

in TChromium there is an OnBeforeDownload event in it we call the function Cont where we pass the path and the second parameter is our dialog window = False, the window will not be = the file is saved.

 procedure TMainForm.crmBeforeDownload(Sender: TObject; const browser: ICefBrowser; const downloadItem: ICefDownloadItem; const suggestedName: ustring; const callback: ICefBeforeDownloadCallback); begin callback.Cont(ExtractFilePath(ParamStr(0)) + suggestedName, False); end;