How to overwrite and redisplay the PDF document that is active in TWebBrowser in Delphi 7

CampsieGlen
CampsieGlen used Ask the Experts™
on
I am using the TWebBrowser component (Delphi 7) to display PDF reports that I create.  I simply assign the pdf to the browser using

WebBrowser1.Navigate('temporary file\myreport.pdf')

This works fine the first time; however, when I run the next report I would like it to use the same temporary file name.  How do I tell the browser (and/or Adobe reader to release the document in order that I may overwrite it?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Have you tried the WebBrowser.Refresh or WebBrowser.Refresh2 method?
These methods do the following:

WebBrowser.Refresh : Reloads the current document

WebBrowser.Refresh2 : Reloads the current document if necessary

Author

Commented:
The problem is that I can't overwrite the document - I imagine because it is still locked by Adobe.  Therefore it's more of an unload function rather than a reload function that I require.

I would like the browser/Adobe to release the document that's in view, so that I can overwrite the actual pdf file with a new version and then redisplay it.

Author

Commented:
I have also tried using navigate to switch to a different, blank pdf file before trying to overwrite myReport.pdf.

This works sometimes but fails others; I have even put a sleep(1000) command after navigating to the blank pdf and before trying to overwrite myReport.pdf, but even this can still fail at times.
I have managed to find a work around to the problem by navigating to a blank pdf (or htm) file before rewriting myReport.pdf.

The key was not to attempt to overwrite the pdf until the browser's DocumentComplete event had fired for the blank document; so far, this appears to work.

However, I would still be interested to know it there's a cleaner/better solution.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial