0

I am starting a PDF. It is being opened in a Chrome tab.

According to Jimis answer in my other question, the following happens:

The Process object that opened the PDF doesn't exist anymore after the main Chrome Process presents the PDF content in a tabbed Window. Find the Chrome Process and check the current title of its Window.

Now I want to close this PDF again. I go through all windows to find the name of the PDF.

I find it by using the PDF's name and adding " - Google Chrome".

The following window is found:

"test.pdf - Google Chrome"

However, when I close this window, the entire browser window is closed, not only the one tab.

Does anybody know why and how to avoid that?

tmighty
  • 10,734
  • 21
  • 104
  • 218
  • You may see if [WebView2](https://learn.microsoft.com/en-us/microsoft-edge/webview2/) meets your needs. To open a pdf: `webView21.Source = new Uri("file:///C:/Temp/test.pdf", UriKind.Absolute);` - where `webView21` is an instance of WebView2. – Tu deschizi eu inchid Jul 17 '22 at 03:02
  • @user9938 Thanks, but I don't have access to the browser... it opens automatically when I open a PDF. You mean I should just switch to another browser like Edge or so, right? – tmighty Jul 17 '22 at 07:04
  • 3
    No, the suggestion is to add a [WebView2](https://learn.microsoft.com/en-us/microsoft-edge/webview2/) Control (Edge Chrome based, replaces the old WebBrowser Control, IE 7/11 based), so you can show the PDF inside your own application -- If you have the PDF bytes - because you're, e.g., generating the PDF yourself - you could also show it directly, without saving to file, with something like this: [Set Webview2 Source directly to a binary stream](https://stackoverflow.com/a/68671066/7444103). Otherwise, just open the PDF file in WebView2 as described. No plug-ins required. – Jimi Jul 17 '22 at 07:30
  • Ah, ok, yes, sure, I was just wondering how I could solve this situation. I don't want to give up. – tmighty Jul 17 '22 at 09:36
  • 1
    The simple way? Send `CTRL + F4` to the Chrome app. It will close the active tab. – Jimi Jul 17 '22 at 13:04
  • Hmmm. :-) This is not really what I mean... :-) – tmighty Jul 17 '22 at 22:49

0 Answers0