Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.
If you find these projects useful please consider becoming a sponsor with Patreon, GitHub or Liberapay.

Opening a PDF File

miket@cbofks.com
Posts: 21
Joined: Tue Aug 03, 2021 7:23 pm

Opening a PDF File

Post by miket@cbofks.com »

Delphi 10.4.2

I have a page that displays links to PDF documents. This page is displayed in a new pop out window with a title of "Case Summary", not in the default browser. Because of sensitive data on this new window I can only show this portion of the screen.

PDF File List
PDF Files.PNG
When I click on a link, the file is automatically downloaded to the Downloads folder which is fine, then the following Downloads dialog is displayed. Here I show the results after clicking all five links:
PDF Files 2.PNG
Notice in the image above that there is a new button added to the Title Bar of the "Case Summary" window for the Downloads dialog. If I click "Open file", the PDF file is opened in yet another new window and this new window is opened behind my "Case Summary" window which means I now have to move the "Case Summary" screen to see the PDF document.

If I move the "Case Summary" window (so I could see the PDF file) while the Downloads dialog is displayed, the Downloads dialog disappears as does the button to open that dialog.

If the close button is clicked on this Downloads dialog, the new button added to the "Case Summary" window will also disappear and the only way to access the Downloads dialog again is to click on one of the PDF file links again.

I have a few questions:

1) If "Open file" is clicked in the Downloads dialog, how do I get it to open in front of the "Case Summary" window?

2) When "Open file" is clicked (or the user clicks the close button on the dialog) the Downloads dialog disappears which is fine, but, the button added to the "Case Summary" window also disappeared. Is there any way to always show the "Downloads" button on the "Case Summary" window (Even if there are no files in the download folder yet, if necessary)?

3) Is there anyway to bypass showing the Downloads dialog and simply open the PDF file in a new window?

4) When a file is downloaded to the Download folder, how do I fetch the name of the file that was downloaded?

Any help is truly appreciated.
You do not have the required permissions to view the files attached to this post.
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Opening a PDF File

Post by salvadordf »

If I understand this issue correctly I would suggest that you use your own Delphi form to show the download progress with your own buttons to open the downloaded files.

That way you can control the downloads window visibility and everything else.

The MiniBrowser demo has a very basic download manager and you can use most of that code.
See the code in these procedures :
  • TMiniBrowserFrm.WVBrowser1DownloadStarting
  • TMiniBrowserFrm.WVBrowser1DownloadStateChanged
miket@cbofks.com
Posts: 21
Joined: Tue Aug 03, 2021 7:23 pm

Re: Opening a PDF File

Post by miket@cbofks.com »

Greetings and thank you for your reply,

I will review that demo and see what I can glean.

You said
your own buttons to open the downloaded files.


Do you know what function I can call to display the downloaded files as I do not immediately see something?

Thanks
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Opening a PDF File

Post by salvadordf »

miket@cbofks.com wrote: Thu Dec 23, 2021 6:20 pm Do you know what function I can call to display the downloaded files as I do not immediately see something?
Use ShellExecute or ShellExecuteEx
https://delphiprogrammingdiary.blogspot.com/2014/07/shellexecute-in-delphi.html
https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecutew
https://docs.microsoft.com/en-us/windows/win32/api/shellapi/nf-shellapi-shellexecuteexw
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Opening a PDF File

Post by salvadordf »

I forgot that you can also open PDF files with TWVBrowser too.

Use a FILE URL as you can see in the MiniBrowser demo.
miket@cbofks.com
Posts: 21
Joined: Tue Aug 03, 2021 7:23 pm

Re: Opening a PDF File

Post by miket@cbofks.com »

Greetings,

I know about opening a file in TWVBrowser using FILE URL. I'm referring how to open/re-open this dialog. I assumed it was some function of the TWVBrowser component.
PDF Files 2.PNG
You do not have the required permissions to view the files attached to this post.
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Opening a PDF File

Post by salvadordf »

That window is handled by WebView2 internally and the API doesn't expose any method to control when or where it's visible.

All we can do at this moment is to create a custom downloads manager.
miket@cbofks.com
Posts: 21
Joined: Tue Aug 03, 2021 7:23 pm

Re: Opening a PDF File

Post by miket@cbofks.com »

Greetings Salvadordf,

I found this link that may help, now if I can just figure out how to get to it. When they list it under experimental does that mean its not available yet? If you can figure it out let me know, if I do I'll respond here.

https://docs.microsoft.com/en-us/microsoft-edge/webview2/reference/win32/icorewebview2experimental11?view=webview2-1.0.1056-prerelease&preserve-view=true

Mike
User avatar
salvadordf
Posts: 4620
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: Opening a PDF File

Post by salvadordf »

Thanks for the information!

Yes, that link shows some of the new features in experimental state from the "prerelease" WebView2 package but WebView4Delphi only uses the features from the "release" version.

Read this for more information about the differences between the "prerelease" and "release" versions :
https://docs.microsoft.com/en-us/microsoft-edge/webview2/concepts/versioning

A quote from that article :
Avoid using the SDK prerelease package to build production apps.
Microsoft publishes a new "release" version of WebView2 runtime every 1 or 2 months and each new version includes some of the features that are now considered stable.

As soon as Microsoft releases those extensions of ICoreWebView2 to control the Download UI I'll add them to WebView4Delphi. :)
miket@cbofks.com
Posts: 21
Joined: Tue Aug 03, 2021 7:23 pm

Re: Opening a PDF File

Post by miket@cbofks.com »

Thanks, Salvadordf
Post Reply