简体   繁体   English

如何在Delphi7中使用TWebbrowser将URL中的PDF保存为PDF文件?

[英]How can I save a PDF from an URL with TWebbrowser in Delphi7 to a PDF FILE?

Is there a way to save a PDF from a TWebbrowser in Delphi 7 to a file? 有没有一种方法可以将PDF从Delphi 7中的TWebbrowser保存到文件中? I can display the PDF in the Webbrowser but How do I save it to a locally PDF FIle? 我可以在Web浏览器中显示PDF,但是如何将其保存到本地PDF文件中?

You can save any webpage to a file with TWebbrowser like this: 您可以使用TWebbrowser将任何网页保存到文件中,如下所示:

Uses 
  ActiveX,
  ...

...

procedure TForm1.SaveDocument(AFilename : String);

var 
  Stream : TFileStream;
  StreamAdapter: IStream;
  PersistStreamInit: IPersistStreamInit;

begin
 if not Assigned(Browser.Document) then
  Exit;
 if Browser.Document.QueryInterface(IPersistStreamInit, PersistStreamInit) = S_OK then
  begin
   Stream := TFileStream.Create(AFilename, fmCreate);
   try
    StreamAdapter := TStreamAdapter.Create(Stream);
    PersistStreamInit.Save(StreamAdapter, True);
   finally
    Stream.Free;
   end;
  end;
end;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM