salvadordf wrote: Thu Oct 11, 2018 7:01 am
Use the
TChromium.OnResourceResponse event and check the
content-type header in the
response parameter.
If it contains "application/pdf" then you can copy the url from the request.
----------------------------------
procedure TIinformSearchFrm.Chromium1ResourceResponse(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest; const response: ICefResponse;
out Result: Boolean);
begin
if ansipos('application/pdf', response.GetHeader('content-type') ) > 0 then
begin
Chromium1.StopLoad;
Chromium1.StartDownload(request.Url) ;
end;
end;
---------------------------------
If I do that, Many same files will be download.
Is it because of the procedure of ChromiumResourceResponse also been tripped by download?
How to avoid this? (I try the following way and it works. Is there another better way? )
Thank you very much!
------------------------------------
procedure Chromium1BeforeBrowse(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest; user_gesture, isRedirect: Boolean;
out Result: Boolean);
begin
// memo1.Lines.Add(request.Url) ;
if ansipos('.',DownPdfUrl)>0 then // or length(DownPdfUrl)>0
begin
Chromium1.StopLoad;
Chromium1.StartDownload(DownPdfUrl) ;
DownPdfUrl:='';
end;
end;
procedure Chromium1ResourceResponse(Sender: TObject;
const browser: ICefBrowser; const frame: ICefFrame;
const request: ICefRequest; const response: ICefResponse;
out Result: Boolean);
begin
memo1.Lines.Add(response.GetHeader('content-type') ) ;
memo1.Lines.Add( browser.MainFrame.Url ) ;
memo1.Lines.Add(request.Url ) ;
memo1.Lines.Add(response.URL ) ;
if ansipos('application/pdf', response.GetHeader('content-type') )>0 then
begin
DownPdfUrl:=request.Url ;
end;
end;
-------------------------------------