Internet Explorer PDF Reader - c#

I apologize for the length of this question, but some background explanation is required.
Background:
I'm working on an internal web application that will display a pdf in an iframe. Adobe Reader X offers a "Read Mode" for displaying the pdf in the browser. This removes the shell and adds a menu box to the bottom of the pdf when the mouse is over the "middle center". In versions prior to X you could use JavaScript to modify the toolbar menu items.
What I Need:
I need to display the pdf in "Read Mode" AND remove all menu items. The computers that are to run this app are basically a kiosk and are literally a computer, monitor and mouse. No printers, no keyboard, no other interactivity.
My question is this:
How can I load a pdf for reading in internet explorer, and disable all interaction except scrolling. That is, no menus, no context menu, and no "shadow bar" when the bottom center is moused over. I've been searching for alternatives to Adobe, and there are some great ones, but the ones I've found that have a browser plugin, do not have a plugin for IE.
If someone know a way to just load the PDF Contents that would be an even better route.
More Information:
If it helps, while this is being built for Internet Explorer, the web-page will be loaded into a windows form that is just a full-screen browser control.
Other things I've tried:
I have also tried positioning a transparent iFrame on top of the pdf iFrame, covering only the displayed content, but leaving the scrollbars intact. This worked perfect if I loaded anything BUT a pdf. If I loaded any other website then it worked as expected (except the scroll wheel of course doesn't scroll the webpage). If a pdf was loaded, then all that would appear is a white square. Use the dev toolbar to remove the transparent iFrame and the PDF looks good.

I've found a good partial solution. A product called PDFObject.
Using it, I can add the following JavaScript to my page:
function embedPDF() {
var myPDF = new PDFObject({
url: 'PathToPdf.pdf',
pdfOpenParams: {
scrollbars: '1',
toolbar: '0',
statusbar: '0',
messages: '0',
navpanes: '0'
}
}).embed('DivToLoadPdfInto');
}
window.onload = embedPDF;
This will embed the pdf into a div and remove the toolbar, statusbar, message, navpanes, but still allow scrollbars. This prevents the shadow box menu from appearing, which is great!
Users can still right-click on the pdf so I'll try the standard Right-Click blockers in JavaScript and edit if I can get something to work.
Edit:
A good resource for URL Parameters can be found here.

Ok, so I have come up with a final solution.
Needs:
Load PDF in iFrame in "Reader Mode" but with no shadow bar
PDF Context Menu should be disabled
Addressing the first need is easy with some caveats. Set the source of the iFrame to "pathToPdf/document.pdf#toolbar=0&navpanes=0". The caveats here are that (in IE at least) once this breaks, then the browser needs to be closed and re-opened to work again. So, what can break it?
User right clicks and opens the navigation pane buttons.
User presses the escape button on the keyboard.
The webpage is loaded into the browser control of a windows form, and luckily once broken there it works fine without closing and reopening. Could still be a problem though for the PDF being viewed. I don't have to worry about the escape key, because the app is running on a KIOSK(basically) and there is no keyboard, only a mouse.
Disabling the context menu has proved to be the most difficult thing to do. The web browser control has a "IsWebBrowserContextMenuEnabled" property that when set to "False" will disable the context menu for the browser. Probably because the adobe reader is a plugin, this does not effect the PDF. With Reader X there is no registry setting (that I could find) or JavaScript method, or general setting that will disable context menu.
I was ready to give up when I remembered something. This is a kiosk, and there is no need for the right mouse button. So the solution; modify the registry and turn off the right click for the internal OS. To do that simply open regedit and goto:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer
Find (or create if it is not there) a DWORD key named "NoViewContextMenu".
A value of 1 will disable right clicking, 0 will enable.
Summary:
Use "pathToPdf/document.pdf#toolbar=0&navpanes=0"
Disable right click in windows registry
Edit:
The registry hack only disables the right mouse button in windows explorer. We are having no luck in finding a good software solution, so we are left with either writing our own custom mouse drivers or simply popping open the mice and removing the physical trigger mechanism.

Related

How would I make a embedded browser in c# non-selectable?

I am currently making an application for someone using an eyegaze system which tracks his eye movements to the screen and uses it as a mouse. When he hovers over a button for a little bit (.6 seconds) it sends a mouse click to the screen where he was hovering. We have an embedded browser within the application that reading the info on the browser is much more important than selecting anything on the browser and with the nature of his device, browsing is selecting if he hovers for too long. How would I go about making the content within the browser read-only, or not able to be selected?
Have you tried putting a transparent panel over the embedded browser? Would be like placing a piece of glass over a book. You can still read it, but you won't be able to touch(select) the page.

Find and Close a Dialog in Firefox using Selenium and C#

Issue: My selenium script is not recognizing and closing a dialog box that pops up when I redirect to a URl that contains file to download. The attached image shows the dialog I am referring to.
I know this has been asked a million times and I have spent at least 24 hours researching and trying other suggestions posted across the web but with no success. I am hoping the attached image will clarify which Firefox dialog box I am referring too.
I have tried the following solutions
1. Creating IAlerts (Alert element is not found)
2. Searching by trying to find the element by xpath (xpath to cancel was not found)
3. WindowsHandler Method (was not able to figure out the window name)
Any help on this would be greatly appreciated. Thank You in advance!
FireFox Dialog
There are several types of "popups".
Javascript dialogs - These are NOT HTML dialogs but are instead Javascript created dialogs. These consist of alert(), confirm(), and prompt() and can be handled with Alert.
HTML dialogs - These take on various forms depending on how they are formatted. If you right-click on the dialog and see the typical context menu for your browser, then it's an HTML dialog. They are part of the DOM of the current page so you can use Selenium to access this just as you would any other page (e.g., no window handles needed).
Browser window - These are actually another browser window that pops up and may look like a dialog, depending on how it's formatted. It's different than an HTML dialog because it can be moved outside of the current browser page frame. You will need to use window handles to access these windows as you would another tab in the browser. Once you get ahold of the window handle, you can access the HTML of the page like any other page.
Browser dialog - these take on various forms but are akin to System dialogs. They are not made up of HTML so they cannot be accessed by Selenium. Other than using a library to access them, you can interact with them in a limited fashion by sending keys such as <SPACE>, <TAB>, <ENTER>, etc.
What you have pictured is a (4) browser dialog. They it takes on different forms depending on the browser you do the action on. Your best course of action is probably send keys. Sometimes, depending on the browser, you can specify settings to autodownload a file to a specific location so that the dialog doesn't come up. I've never used this so I can't direct you there.
I was able to find and close a download dialog box by checking the amount of open windows after the dialog appears. This solution worked for me.
Find a link to open a dialog and click it:
var link = MyBrowser.Driver.FindElement(OpenQA.Selenium.By.Id("Button"));
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
js.ExecuteScript("arguments[0].click();", link);
Get the new window count after the dialog opens:
var newWindowCount = MyBrowser.Driver.WindowHandles.Count;
Switch to the newly opened dialog and close it:
MyBrowser.Driver.SwitchTo().Window(MyBrowser.Driver.WindowHandles[newWindowCount-1]);
MyBrowser.Driver.Close();

WPF / C# Display of Acrobat Toolbar

I'm creating a WPF application that has viewing of PFDs built into it. I use WindowsFormsHost method to view the PDF:
<WindowsFormsHost x:Name="PDFViwer"/>
var pdfViwer = new AdobePDFViewer(#"E:\temp\test\testFile1C.pdf");
this.PDFViwer.Child = pdfViwer;
I've noticed that when I view some files (such as electronic version of books), the Acrobat Toolbar will display automatically, such as this:
However, some other files that are.. let's say created from a Word Document or sent to print to PDF, will display the document in Read Mode, which brings up a menu bar at the bottom if you hover towards that area, such as this:
I like the second better than the first; however, due to the fact that some users might not know that hovering towards the bottom will display those options, I want to be able to force those options to display.
If I click the Acrobat symbol on the popup menu that has a caption of Show Acrobat Toolbar, it'll go into the mode where the Toolbar will display at the top... but once again, the user has to know of the popup menu existence in the Read Mode.
Is there a way to force the Toolbar to display by default or a way to make a custom button force mode switch?
Adobe doesn't have the greatest developer documentation in the world... why can't everyone be like Oracle. They'll provide a list of methods, but don't provide a clear list of possible parameters or a very clear description of those methods.. So I've been playing with this.axAcroPDF1 methods and one of them does something halfway to what I'm trying to accomplish: this.axAcroPDF1.setShowToolBar(true). However, what that does is displays the Adobe Reader Toolbar at the top of the document while still in Read Mode. So, I have a toolbar on top and the dynamic toolbar on bottom, which is a bit messy in my opinion. I can't figure out how to switch modes... there are more methods, but I can't find the list of available enumeration parameters for them.
I don't believe how ridiculously hard it is to find information on Adobe products if you're a developer... I guess I was spoiled by Oracle's incredible documentation of Java. Anyways, I've even read through this "lovely" document, and I still can't figure it out: http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/acrobat/pdfs/iac_api_reference.pdf
Try to customize current view as described in link

UI Automation cannot control embedded browser

This is about testing a desktop application. I have been trying to click a hyperlink on an embedded browser of a Windows form. I could move the mouse anywhere if the component (buttons, or whatever) is part of the form, but elements inside the browser, i can't seem to control at all....sigh.....yes, I could move the mouse if I use the screen coordinates but I plan to control the embedded browser using Watin, etc..without opening a new IE....Using Microsoft's UISpy tool (when I hover the cursor to the link..it shows a Pane ControlType)....the hyperlink is part of the tree structure but only the name property is available...some of the parent's properties are blank....
I tried extending the example from the link below
http://archive.msdn.microsoft.com/uiautomation
and this is where i'm stuck (I have tried FindChildByName and other related methods too...sigh..no luck):
var commontab=AutomationElement.RootElement.FindFirstChildHavingDescendantWhere(new[] { new PropertyCondition(AutomationElement.NameProperty, "Search")});
Mouse.MoveTo(menutab.GetClickablePoint().ToDrawingPoint());
Mouse.Click(MouseButton.Left);
Somehow the mouse cannot find the 'Search' hyperlink...sigh...please guys...any ideas??
Would it not be a simpler idea to split this into 2 testing strategies? The first is testing the desktop UI, buttons etc. as you are. The second is to test the html which is to be placed within the embedded browser frame.
You shouldn't be testing that the embedded browser works, that's Microsofts job. The only testing that you may want to do on the frame is to ensure that it's content is loaded, that the call is to the correct (internal) url etc.

How to show a web page in full screen mode without statusbar and addressbar in all browsers?

How to show a web page in full screen mode without statusbar and addressbar in all browsers and it should not show the taskbar also.
You can't do this with JavaScript - and that's a good thing...I don't want a full screen advertisement in my face, do you?
Pseudo-out-of-browser plugins can do some of this though, Flash and Silverlight for example...but you can't do it with just a page and JavaScript. Browsers (especially newer ones) actively prevent most resizing and windows-without-bars behavior.
If I want MY browser to be in full screen mode, I will press F11.
It is MY browser. Not yours.
You cannot do this, as Javascript can only change things inside the webpage. It cannot change the behaviour of the browser itself.
You cannot do this in javascript. The reason is that someone might make a screen that looks like a windows lock screen and force users to type in their username/password. Its called phishing and illegal : http://en.wikipedia.org/wiki/Phishing . For right usage you can ask the user to opt into it (the user has to click a button) using Silverlight / Flash. However in this case the keys that function are limited. So you cannot get the user to type alphanumeric keys. Keys commonly used in games (e.g space / arrow keys) will function. So will mouse clicks. With Silverlight if the user accepts you application to be Trusted (FullTrust) you can even capture all keys : http://timheuer.com/blog/archive/2009/11/18/whats-new-in-silverlight-4-complete-guide-new-features.aspx
I did not get what really you wants?
You want code to your page OR manually you want to do with browsers.
If while browsing you want to do IE, Mozilla, Google chrome etc. will Do it with "F11" key (Short cut key)
(Highly NOT RECOMMENDED, but you can try *)*If you want javascript for this, here it is...
<SCRIPT LANGUAGE="JavaScript">
function fullScreen(theURL) {
window.open(theURL, '', 'fullscreen=yes, scrollbars=auto');
}
</SCRIPT>
<--- BODY OF DOCUMENT -->
<body onload="fullScreen('popup_webpage.htm');">
this will open the webpage in new pop-up on page load.

Categories