Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to save PDF content to file using IWebBrowser2

16 views
Skip to first unread message

ningju...@lexisnexis.com

unread,
Mar 31, 2005, 11:29:51 AM3/31/05
to
Can anyone tell me how can I save the PDF content in the browser to a
file on teh file system using IWebBrowser2? I try

ExecWB(OLECMDID_SAVEAS, OLECMDEXECOPT_DONTPROMPTUSER, &pvaIn, &pvaOut);

It prompt user for file name. I don't want to prompt user because I
know what file to save. Microsoft said there is no way to save to a
file without prompt user.

Is there any way I can get the binary content of the PDF file so that I
can save to file my self?

Of course I can always download the file again from Internet and save.
But this is a performance waste. The browser already download the PDF
file and I don't want to download it again.

Sample codes will be greatly appreciated.

Cristian Amarie

unread,
Apr 3, 2005, 1:42:29 AM4/3/05
to
(The same answer as for one of the previous posts...)

http://www.delphidabbler.com/articles.php?article=14
Although the sample code is Delphi, it may help.
Probably you'll have to use a type library and use IPersistStreamInit to
save the full HTML file.

Cristian Amarie

<ningju...@lexisnexis.com> wrote in message
news:1112286591.0...@l41g2000cwc.googlegroups.com...

ningju...@lexisnexis.com

unread,
Apr 6, 2005, 4:31:06 PM4/6/05
to
I try thi. It works if the browser hold html page. If does not work if
the browser hold PDF page. Here is my code:

HRESULT hr;
IDispatch* pHtmlDoc = NULL;
IPersistStreamInit* pPersistStreamInit = NULL;

hr = m_pIE->get_Document( &pHtmlDoc );
if ( !SUCCEEDED(hr) || pHtmlDoc == NULL ) {
throw EpactException("Failed to get Document");
}
hr = pHtmlDoc->QueryInterface( IID_IPersistStreamInit,
(void**)&pPersistStreamInit );
if ( !SUCCEEDED(hr) || pPersistStreamInit == NULL ) {
throw EpactException("Failed to get IID_IPersistStreamInit");
}


HGLOBAL hGlobal = GlobalAlloc( GPTR, 2000000 );
if (!hGlobal) {
throw EpactException("GlobalAlloc() failed");
}

LPSTREAM pStream = NULL;
hr = CreateStreamOnHGlobal( hGlobal, FALSE, &pStream );
if ( !SUCCEEDED(hr) || pStream == NULL) {
throw EpactException("Failed to create stream");
}

hr = pPersistStreamInit->Save(pStream, TRUE);

The last line (Save())return errorcode 0x80170057 if the content is
PDF.

stack

unread,
Jun 30, 2005, 11:35:02 PM6/30/05
to
because the pdf is a activeX control, you should find the object and call
it's Invoke method,you can find the ID,and invoke it by IDispath.
0 new messages