![]() |
How to Save PDF from web
Hello,
I'm looking for a way to load a PDF from a web URL and then save it to the local disk automatically. I've used the Adobe TPdf control imported in Delphi as an ActiveX control. With this control I can just put in a URL with the PDF address, but I see NO Save function in the TPdf object.... On screen, after loading, in the control there is a save button that will save the document, but I want to save the document in Delphi after loading without a user pressing this save button. Anyone know how this works with TPdf? Maybe another way to do this (with TWebbrowser) ?? Greets, Delphi-Lover. |
Re: How to Save PDF from web
Hello Delphi-Lover,
if you don't insist on viewing the pdf document in question you could download it to your disk with this handy routine from the net (never tried myself):
Delphi-Quellcode:
Wish you success
uses Wininet;
function GetInetFile(const fileURL, FileName: String): boolean; const BufferSize = 1024; var hSession, hURL: HInternet; Buffer: array[1..BufferSize] of Byte; BufferLen: DWORD; f: File; sAppName: string; begin Result:=False; sAppName := ExtractFileName(Application.ExeName); hSession := InternetOpen( PChar(sAppName), INTERNET_OPEN_TYPE_PRECONFIG, nil, nil, 0 ); try hURL := InternetOpenURL(hSession, PChar(fileURL), nil, 0, 0, 0); try AssignFile(f, FileName); Rewrite(f,1); repeat InternetReadFile(hURL, @Buffer, SizeOf(Buffer), BufferLen); BlockWrite(f, Buffer, BufferLen) until BufferLen = 0; CloseFile(f); Result:=True; finally InternetCloseHandle(hURL) end finally InternetCloseHandle(hSession) end end; marabu |
Re: How to Save PDF from web
Hallo Marabu,
Many Thanks!! :love: The code works OK and I can use it as it is. Maybe interesting to know if this is also possible with the TPdf control. anyone???? Greetings, Delphi_lover |
Re: How to Save PDF from web
Zitat:
|
Re: How to Save PDF from web
Hi folks,
I just imported the Adobe Acrobat 7.0 Browser Control Type Library 1.0 just to find out what Bernhard mentioned - the interface is a very scarce resource. But although the requested functionality is not exported directly by the COM interface, the functions are there all the same. The Browser Control is perfectly capable to write pdf documents to your hard drive. By processing this tiny piece of code the well known toolbar is exposed and you can save a copy of the document:
Delphi-Quellcode:
Since the LoadFile() method does not accept a URL, I conclude, that the Internet Explorer does the download part and knows a way to inform AcroPdf. Those who have access to the Acrobat SDK should be able to find out about the other interfaces supported via AcroPdf.ControlInterface or the command identifiers handled by AcroPdf.DoObjectVerb().
procedure TDemoForm.DemoButtonClick(Sender: TObject);
begin with AcroPdf do begin setShowToolbar(true); LoadFile('c:\daten\download.pdf'); end; end; The rest of us can use the function GetInetFile() posted above. Or give the indy http client a try:
Delphi-Quellcode:
So long
procedure Download(url, filename: string);
var fs: TFileStream; http: TIdHttp; begin fs := TFileStream.Create(fileName, fmCreate); http := TIdHttp.Create(nil); http.Get(url, fs); http.Free; fs.Free; end; marabu |
Alle Zeitangaben in WEZ +1. Es ist jetzt 22:10 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz