1

I am using the System.Windows.Controls.WebBrowser web browser to enable users to view PDF files from within my WPF application.

I now want to prevent the user from having any options for interaction with the content displayed in the browser (i.e. they should not be able to print/ save/ highlight text/ copy any of the content displayed in the browser).

How would I do this?

I have added the WebBrowser to the application with the line:

System.Windows.Controls.WebBrowser browser = new System.Windows.Controls.WebBrowser();

and am specifying the path of the file that they are viewing from within the code, but also giving them the options to select other files to view by using File -> Open and browsing to the location of the file that they want to open.

I couldn't find anything in the MSDN WebBrowser docs that indicated how I could disable the Save or Print buttons, 'right-click' functionality, or text highlighting... does anyone have any suggestions?

Noble-Surfer
  • 3,052
  • 11
  • 73
  • 118
  • Just a guess, but wouldn't this be as simple as saying browse.IsEnabled=false? – adminSoftDK May 24 '16 at 16:31
  • I don't want to disable the browser- as I want to display the content in it, just don't want to allow the user to interact with that content in any way, as information displayed there may be confidential... – Noble-Surfer May 24 '16 at 16:33

1 Answers1

1

The problem is not the WebBrowser. You are opening a PDF file within it, so it's either a plugin or built-in viewer. Controlling that is outside of the WebBrowser properties and events.

You should consider using an actual PDF viewer control, such as ones suggested in this topic.

Community
  • 1
  • 1
Chris Fannin
  • 1,284
  • 1
  • 10
  • 16
  • Thanks for the link. I'll have a look through the viewers listed, and give one a try. Do you happen to know whether any of these support the functionality to enable you to view files with your own extension? For example, if I was to build a file with extensions `.xyz`, could I use one of these viewers to view that file? I would assume I would need to do some work on the viewer to enable the custom extension, but is it theoretically possible? – Noble-Surfer May 25 '16 at 08:18
  • I've decided to use MoonPdf (https://github.com/reliak/moonpdf), but I'm not sure how I 'include' this in my application... any suggestions? – Noble-Surfer May 25 '16 at 10:35
  • If the custom extension is just a renamed PDF file, then you could display it. Otherwise, you'll need to swap out to whatever viewer is appropriate. To use MoonPdf, you would need to get one of the distributions from Sourceforge: https://sourceforge.net/projects/moonpdf/files/MoonPdf-0.3.0/ . Keep in mind that it looks like that project hasn't been touched in 3 years (it's unfortunate that a lot of OSS tends to go that way), it might not work for some files, and it can possibly quit working with newer PDF files. – Chris Fannin May 25 '16 at 14:27
  • @someone2088 If you're going this route (which I saw your other post), can you please mark this answer as accepted? :-) – Chris Fannin May 25 '16 at 16:45
  • Thanks for the suggestion- I'm trying to go this route (just trying to view simple PDFs inside my application at the moment), but I can't seem to get my app working with MoonPDF- when I try to add one of its `MoonPdfPanel`s to my application in the XAML, I get a compile error telling me that the 'type' cannot be found, and to verify that I am not missing an assembly reference, and that all referenced assemblies have been built`... I've tried building the MoonPdf source, but I get a compile error that says: – Noble-Surfer May 26 '16 at 13:27
  • `Severity Code Description Project File Line Suppression State Error The command "xcopy C:\...\moonpdf\src\..\bin\MuLib\AnyCPU\libmupdf.dll C:\...\MoonPdf\bin\Debug\ /Y" exited with code 4.` – Noble-Surfer May 26 '16 at 13:27
  • I've updated the other post: http://stackoverflow.com/questions/37443128/wpf-xaml-compile-error-the-name-does-not-exist-in-the-namespace/ – Chris Fannin May 26 '16 at 13:48
  • Ok, so now I have the PDF viewer displaying PDFs correctly- how do I disable to controls such as print/ save, etc, which is what I was originally trying to do? – Noble-Surfer May 26 '16 at 15:31
  • If you're using the viewer, it doesn't have those options. In the example I made in the other post, I can't select text, there isn't a context menu, there aren't any button overlays for saving or printing, etc. – Chris Fannin May 26 '16 at 15:37