AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

How to Save PDF from web

Ein Thema von Delphi-Lover · begonnen am 5. Sep 2005 · letzter Beitrag vom 5. Sep 2005
Antwort Antwort
Delphi-Lover

Registriert seit: 19. Okt 2004
Ort: Amsterdam
30 Beiträge
 
Delphi 2005 Professional
 
#1

How to Save PDF from web

  Alt 5. Sep 2005, 14:17
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.
Rob
  Mit Zitat antworten Zitat
marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#2

Re: How to Save PDF from web

  Alt 5. Sep 2005, 14:29
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:
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;
Wish you success

marabu
  Mit Zitat antworten Zitat
Delphi-Lover

Registriert seit: 19. Okt 2004
Ort: Amsterdam
30 Beiträge
 
Delphi 2005 Professional
 
#3

Re: How to Save PDF from web

  Alt 5. Sep 2005, 14:39
Hallo Marabu,

Many Thanks!!

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
Rob
  Mit Zitat antworten Zitat
Benutzerbild von Bernhard Geyer
Bernhard Geyer

Registriert seit: 13. Aug 2002
17.171 Beiträge
 
Delphi 10.4 Sydney
 
#4

Re: How to Save PDF from web

  Alt 5. Sep 2005, 14:50
Zitat von Delphi-Lover:
Maybe interesting to know if this is also
possible with the TPdf control. anyone????
No, it isn't. The Interface that is provided by Adobe for the Adobe Viewer is a minimum to let the control work in the IE. Nothing else is supported by Adobe, so only very few Methodes are exported in the COM-Interface.
Windows Vista - Eine neue Erfahrung in Fehlern.
  Mit Zitat antworten Zitat
marabu

Registriert seit: 6. Apr 2005
10.109 Beiträge
 
#5

Re: How to Save PDF from web

  Alt 5. Sep 2005, 16:08
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:
procedure TDemoForm.DemoButtonClick(Sender: TObject);
begin
  with AcroPdf do begin
    setShowToolbar(true);
    LoadFile('c:\daten\download.pdf');
  end;
end;
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().

The rest of us can use the function GetInetFile() posted above. Or give the indy http client a try:

Delphi-Quellcode:
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;
So long

marabu
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 16:43 Uhr.
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz