Welcome Guest Search | Active Topics | Sign In | Register

Webbrowser viewing PDF / No Contextmenu Options
Jason R.
Posted: Wednesday, June 24, 2015 4:42:07 PM
Rank: Member
Groups: Member

Joined: 6/12/2015
Posts: 20
Using the latest version 2015.1.74.108

When viewing a PDF file in the WebBrowser, right-clicking brings up the default context menu.

The expected behavior is to have the normal Adobe PDF viewer context menu popup which allows the user to "Rotate clockwise"

I tried e.Menu.Items.Clear() in the BeforeContextMenu event, but that just makes NO context menu appear.


It seems as if the Plugin's contextmenu is not taking in precedence.
eo_support
Posted: Thursday, June 25, 2015 10:19:12 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,072
Hi,

This is not supported in the current build. EO.WebBrowser 2015 uses its own built-in PDF viewer, so it's not the plugin from Adobe PDF Viewer. Chrome does implement "Rotate Clockwise" and "Rotate Counterclosewise" context menu item when it loads PDF file, but we did not implement these two context menu items.

Thanks!
Jason R.
Posted: Friday, June 26, 2015 11:48:21 AM
Rank: Member
Groups: Member

Joined: 6/12/2015
Posts: 20
For now, I have checked for the .pdf extension in the BeforeNavigate and NewWindow events, cancled the request, and open the URL in my own PDF viewer using Acropdflib.dll

It would be nice if you implemented the rotate functionality in to the build in PDF viewer.
eo_support
Posted: Friday, June 26, 2015 12:38:06 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,072
Thanks for very much for your valuable feedback. We will add this into our list. I do not believe this will be a priority now so it might take sometime before we can have that.
Jim B
Posted: Monday, August 3, 2015 10:54:45 AM
Rank: Advanced Member
Groups: Member

Joined: 1/31/2015
Posts: 70
Hello,

You say that "EO.WebBrowser 2015 uses it' own build-in pdf viewer". Is there any documentation available on this? For version 2014, EO.WebBrowser used to open the pdfs using e.g. adobe reader plugin. Now it doesn't respond to pdf links at all. Any ideas?
eo_support
Posted: Monday, August 3, 2015 11:07:42 AM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,072
Jim B wrote:
Now it doesn't respond to pdf links at all. Any ideas?


This can be an issue. Chrome has its own PDF plugin that is included in EO.WebBrowser 2015. In 2014 it uses the "generic" NPAPI plug-in from Adobe. We will look into this and see what we can find. I imagine the solution would be either to make the Chrome PDF plug-in work as expected or add a switch to allow you to use the Adobe Plugin.

Thanks!
Jim B
Posted: Monday, August 3, 2015 11:22:07 AM
Rank: Advanced Member
Groups: Member

Joined: 1/31/2015
Posts: 70
Can we bypass the chrome pdf plugin in the current version? My understanding is no...
eo_support
Posted: Monday, August 3, 2015 12:04:46 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,072
Jim B wrote:
Can we bypass the chrome pdf plugin in the current version? My understanding is no...


This is what we will look into. The current answer is no.

Thanks!
Jim B
Posted: Monday, August 3, 2015 12:13:57 PM
Rank: Advanced Member
Groups: Member

Joined: 1/31/2015
Posts: 70
To help, here's our case that stopped working with version 2015. It's not a matter of Chrome plugin I think:

we set up the new window listener:

web_view.NewWindow += new EO.WebBrowser.NewWindowHandler(web_view_NewWindow);

...

private void web_view_NewWindow(object sender, EO.WebBrowser.NewWindowEventArgs e)
{
try
{
if (e.TargetUrl.Contains(".pdf") || e.TargetUrl.Contains("showpdfservlet"))
{
//If it is a pdf. We want to be opened from the default pdf pc viewer.
//We use a threadrunner so that no webview window needed.
//We need a webview object so that the redirections of the website can take place.

e.Accepted = false;
EO.WebBrowser.ThreadRunner threadRunner = new EO.WebBrowser.ThreadRunner();
EO.WebBrowser.WebView webView = threadRunner.CreateWebView();

webView.BeforeDownload += new EO.WebBrowser.BeforeDownloadHandler(web_view_BeforeDownload);
webView.DownloadCompleted += web_view_DownloadCompletedChild;

webView.Url = e.TargetUrl;
}
}
catch (Exception ex)
{
...

}

}

it appears that the code never runs into web_view_BeforeDownload or web_view_DownloadCompletedChild methods. It's like the download is never initiated.

Jim B
Posted: Monday, August 3, 2015 12:29:05 PM
Rank: Advanced Member
Groups: Member

Joined: 1/31/2015
Posts: 70
What worked in the new window handler is this:



e.Accepted = true;
PdfPopUpWindow newWindow = new PdfPopUpWindow();
newWindow.Owner = Application.Current.MainWindow;
e.WebView.Activate += new EventHandler(web_view_Activate);

e.WebView.BeforeDownload += new EO.WebBrowser.BeforeDownloadHandler(web_view_BeforeDownload);
e.WebView.DownloadCompleted += web_view_DownloadCompleted;

newWindow.wc.WebView = e.WebView;
newWindow.Show();


but this does not use the Threadrunner solution that I mentioned at my previous post. The handler above works fine your embedded Chrome pdf plugin.

I hope it helps somehow.

Regards,

Jim
eo_support
Posted: Monday, August 3, 2015 2:18:08 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,072
Hi,

That makes sense. I thought you meant the PDF internal links (bookmarks) didn't work. For Url links, you do need to handle NewWindow.

I am not sure exactly what you are trying to do with ThreadRunner or BeforeDownload/DownloadCompleted event though. BeforeDownload/DownloadCompleted event is only triggered for a resource that the WebView can't display. Since the browser engine can display a PDF file, so it shouldn't trigger BeforeDownload event for a PDF file.

Thanks
Jim B
Posted: Tuesday, August 4, 2015 3:10:15 AM
Rank: Advanced Member
Groups: Member

Joined: 1/31/2015
Posts: 70
Jason R. wrote:
For now, I have checked for the .pdf extension in the BeforeNavigate and NewWindow events, canceled the request, and open the URL in my own PDF viewer using Acropdflib.dll


The reason for using the ThreadRunner and BeforeNavigate etc is exactly the one that Jason describes. The need to handle the pdf by downloading and opening with external program. ThreadRunner because it's headless, no need to show, only to download at the background at another thread.

For the sake of completeness:

Code: C#
private void web_view_BeforeDownload(object sender, EO.WebBrowser.BeforeDownloadEventArgs e)
        {
            e.ShowDialog = false;
        }


and the download handler

Code: C#
private void web_view_DownloadCompletedChild(object sender, EO.WebBrowser.DownloadEventArgs e)
        {
            try
            {
                FileInfo file = new FileInfo(e.Item.FullPath);
                string filename = file.Directory.FullName + "\\" + DateTime.Now.Ticks +"_"+ file.Name;
                file.MoveTo(filename);

                Thread t = new Thread(delegate()
                {
                    Process p = System.Diagnostics.Process.Start(filename);

                    p.WaitForInputIdle(1000);

                    IntPtr splashwindow = FindWindowByCaption(IntPtr.Zero, "*" + System.IO.Path.GetFileName(filename)+"*");
                    SetForegroundWindow(splashwindow);

                    while (!p.HasExited)
                    {
                        Thread.Sleep(3000);
                    }

                    try
                    {
                        File.Delete(filename);
                    }
                    catch (Exception ee)
                    {
                        //swallow
                    }
                });
               
                t.IsBackground = false;
               
                t.Start();
            }
            catch (Exception ex)
            {
                string errorMsg = "problem with download handler";
                ExceptionPolicy.HandleException(new ApplicationException(errorMsg, ex), "UIPolicy");
            }
            finally
            {
                ((EO.WebBrowser.WebView)sender).Dispose(); //We kill the webview created from the threadrunner
            }
        }


Both handlers stopped working with version EO.2015. No exceptions logged. The code above is a continuation of the code at "Monday, August 03, 2015 7:13:57 PM".

My gut tells me that Threadrunner may not be properly started from the new window handler.

I also have hijacked this forum post. I'm sorry, it seems it's not pdf related anymore

jim
eo_support
Posted: Wednesday, August 5, 2015 6:04:46 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,072
Hi Jim,

The reason that both handler stopped working is because in 2015 the browser engine knows PDF as a "supported format". For any format that the browser engine understands, it won't trigger download event. For example, if you load an image into the browser engine, the browser engine just displays it instead of "downloading" it. EO.WebBrowser 2014 would download a PDF file without a plug-in, but EO.WebBrowser 2015 will not trigger download for PDF file at all because it has a built-in plug-in to display it. Your event handler would stop working in 2014 as well if you have Adobe PDF plug-in installed.

One way to achieve what you want to do is to use .NET's built-in HttpRequest class to download the PDF file directly from the server. You don't need a web browser engine just to download a file.

Thanks!
Jim B
Posted: Thursday, August 6, 2015 4:36:26 AM
Rank: Advanced Member
Groups: Member

Joined: 1/31/2015
Posts: 70
Hey, thanks for the reply. It makes sense.

The code above worked at v2014 with pdf downloads even with plugins installed, because indeed I had the "do not search for plugins" flag set at EO.Browser's initialization.

As I understand from your reply, v2015 cannot do this unless you guys introduce a "disable all plugins" flag. Is this about right?

Regards,

Jim
Jim B
Posted: Tuesday, September 8, 2015 10:09:34 AM
Rank: Advanced Member
Groups: Member

Joined: 1/31/2015
Posts: 70
As a followup,

I tried to use the

Code: C#
EO.WebBrowser.Runtime.DisableBuiltInPlugIns = true;


parameter so that I handle the pdfs manually.

But, as I understand from your words, download will never happen for a pdf, even with the above flag set.

Is this right?

Is there any way to force a pdf download event?

Thanks

Jim
eo_support
Posted: Tuesday, September 8, 2015 10:30:33 PM
Rank: Administration
Groups: Administration

Joined: 5/27/2007
Posts: 24,072
Jim B wrote:
But, as I understand from your words, download will never happen for a pdf, even with the above flag set.


This is not correct. Download will not happen if there is a plug-in that can handle PDF. This plug-in can be:

1. The built-in PDF plug-in in 2015 version. You can disable this plugin by DisableBuiltInPlugIns to true;
2. Adobe NPAPI PDF plug-in installed on your system. By default, if you install Adobe Reader on your system, then this plug-in will get installed. You can disable this plugin by setting this property to false:

http://www.essentialobjects.com/doc/eo.webbrowser.runtime.autoscancommonplugins.aspx

Once you disable both #1 and #2, download should occur for PDF file.

Thanks!
Jim B
Posted: Wednesday, September 9, 2015 4:39:56 AM
Rank: Advanced Member
Groups: Member

Joined: 1/31/2015
Posts: 70
You are right! After adding the second parameter (autoscancommonplugins = false) downloads worked again!

Thanks for helping

Jim


You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.