Showing multiple PDF Files in WebBrowser control (Windows Form) - c#

I’m trying to show PDF files in Windows Form WebBrowser control. I do this by WebBrowser.Navigate() method. It is work when I want show one PDF file, which is not enough for me. I need when a user clicks a button , WebBrowser show another PDF file. What I have to do?

Avoid using WebBrowser control just to show a pdf. Try using one of the many free PDF libraries available for .net such as PDFSharp.
This will allow you to draw pdf's on to the Form and using TabControl you can create tabs programmatically and place a new pdf viewer inside of the tab.
You could easily make a 2 different files PDF viewer (side by side or top and bottom) by using the PDFSharp. Or you can use the ActiveX control for Adobe Reader.
Edit: It was my understanding that PDFSharp can render pdf's directly. This can only be done by exporting the page to a Jpeg/Png and then displaying the images. Sorry for any confusion.

At your place I'd do tabControl, and foreach tabControl, I'd put a webbroswer inwhich there would be a PDF by Tab.
EDIT : A WebBroswer isn't like internet explorer. Internet Explorer has the "Feature" of having multiple tabs (just like Chrome, etc). The WebBroswer Element is only the content of the tab :)
EDIT2 : After many years into this, I would recommend using a PDF library also. As a prototype usecase it might work, but in real world, we never know how many there will be. the best would probably to: either let the option to the user to open in a competent software i.e. Acrobat Reader where tab is natively used (DC), or use a PDF Library.

What i think is that you are facing a very simple navigate issue here. I have worked out a project for you, take a look at it, I hope it will solve your issue.
download here.

Related

WPF WebBrowser opens Adobe Reader 10 instead of displaying the pdf inside the browser

I'm facing a quite difficult problem. I inherited a software framework (roughly 100k lines of code) and now I want to display PDF files within this software. Since I can put WPF UserControls into this, I created a light-weight UC containing a WPF WebBrowser. I then used the Navigate() method to load a PDF document. Unfortunately, the WebBrowser does not display the PDF document, but instead opens up Adobe Reader 10 in a separate window/process. It will display HTML just fine, but even embedding the PDF inside HTML (using the <object>-tag or <iframe> did not display the pdf though, but caused Adobe Reader to open). When I use the same code in a standalone app (with no code from the framework), the WebBrowser displays the PDF as expected.
Modifying the Registry to allow feature emulation did not solve this issue either.
I've been looking for a solution for days now and cannot seem to find anything. So here is were I hope to get some insight:
How do I get my standalone app to behave like my framework? I did not seem to find anything about this either, but I hope that by managing this, I'll be able to fix the issue with my framework.
Okay, I kinda feel dumb for not paying attention to this:
My test app works because its being compiled in x86, while my Framework uses x64. Apparently, the WPF WebBrowser (same's true for the WinForms WebBrowser Control) are not able to render PDFs when they are running in an x64 app. Once it changed the target platform in my test app from x86 to x64, it also began opening up Adobe Reader...

Display PDF preview in WPF and search for a phrase

I need to display PDF preview in WPF control, programmatically search for text in it, highlight found text and be able to copy text. Sounds simple, but I am struggling with different approaches for a week already.
Here what I have considered:
Find PDF controls for WPF
Most of them just render PDF as images or cost too much. Royalty or subscription fee is not an option.
The only suitable control that I found is:
http://www.syncfusion.com/products/wpf/pdf-viewer
I was even able to do searches programmatically with reflection hacks, but it renders text too blurry (Syncfusion promise to fix this soon) and load pages with a noticeable lag during scrolling.
Using AcroPDFlib as an ActiveX component
I was not able to make it work with the latest Adobe reader on Windows 10 64-bit. But I don't see methods for search anyway, so I dropped this. Also, it seems that it is not free for commercial use:
AcroPDFlib, AxAcroPDFLib commercial use
Load PDF in WebBrowser control
It works and even allow searches, but it can search only for single words which make this search useless. If I search for "big apple" it highlights all big and apple and also open this search panel that cover the document.
Send CTRL+F and text to the browser control to trigger search
I have tried to use this library
http://inputsimulator.codeplex.com/
But PDF in browser control seems to ignore keystrokes from there or maybe I am doing something wrong. Still considering this option.
Use pdf.js in browser control
IE7-based control from WPF won't support that, so I need another browser control. And it seems that I also need to start nodejs to make it work. Seems like a too much overhead for this task. And also it is not clear does PDF.js supports search for a phrase or not.
But I am still not discarding this option. Does anyone were able to make it work inside WPF?
Any suggestions?

Image Thumb Previews for SharePoint

Is there a way to generate an image preview of images added into a SharePoint list?
The scenario is the following:
For image files (.jpg, .tif, .png) that are added into a SharePoint document library which are then listed or viewed via "list view web part on another page" when the user hovers over any of the image files a popup window or anything similar should be displayed showing a preview of the image. Is this possible to achieve in SharePoint and how would this be done.
Would css alone achieve this, or will it require c# code behind.
Many thanks,
Why not use SharePoint picture libraries ? There you got thumbnails, preview and so on.
Or you could make an custom solution using ex. jquery fancybox .
I would suggest that you use standard SharePoint or connect the hover effect on the picture library on your own list.
see
http://office.microsoft.com/en-us/windows-sharepoint-services-help/working-with-sharepoint-picture-libraries-HA001123335.aspx
http://www.youtube.com/watch?v=olaGyX4g2Cc

Disable PowerPoint features using C#

My scenario:
I have a requirement in my project(C#).I need to give the user only reading capability for my powerpoint presentation opened thru my application.All other featues like cut,copy,paste,save,saveas,print,right click context menus should be disabled.How can i achieve this in powerpoint programatically using c#? can anyone extend their help?
Can you publish the ppt as pps and use that file instead?
Just export each slide as a JPG or PNG and display those: Slide.Export. This would be for static slide views. If you want to retain animations, transitions, video/audio and navigation features for your PPT/PPTX, a PowerPoint-to-Flash converter is a better way to do this. iSpring makes a free version of their converter: www.ispringfree.com.
You should use the Powerpoint COM component, kind of like whats described here...
Using C# to display powerpoint
I have only used Word and Excel ones, and i must say they are extremely easy to use.
Or is you MUST make it completely read-only, id suggest writing your own ODF parser, or investigating in the ODF COM component, maybe that could work as well :)
One solution could be to use something like Aspose.Slides to render the Slides to TIFF or PDF and then display those inside your application.
If you have a low number of powerpoint presentations, you can look into Information Rights Management or use the Permissions Object. (Disclaimer:I have not used this)
Assuming that you're using Powerpoint Automation. Get hold of the PowerPoint.Application object and then loop through the CommandBars property and for each command bar, set Visible to false.
This should remove the command bars at least. And there might be other properties on the Application object that lets you disable context menus, but I've never really used powerpoint, so I'm not sure which ones.
I don't think that there's any good way of disabling printing etc altogether though. However, this MS KB article discusses a hacky way of dismissing any dialogs automatically, so assuming that the print/save etc would always bring up a dialog (which I'm not sure off) you might be able to use something from there: How To Dismiss a Dialog Box Displayed by an Office Application with Visual Basic
It's all VB code in that article, but the ideas will be similar.

Rotate view of PDF on a WinForm

I have to display a PDF inside a winform (c# on .net 2.0 framework). For now, I am using the ActiveX PDF control provided by Adobe. I have to disable the entire control so that a user can't print or save via right-click or hotkeys. Unfortunately, many of the documents need to be rotated (just viewed, not permanently saved that way). I'd like to allow them to rotate the view by pressing a button control. I've tried enabling the control then programmatically sending the hotkeys (ctrl shift +) using SendKeys and SendInput but the timing issues make this a non-viable solution.
I've asked on the proper Adobe boards and they said it was not possible being that all of my clients will only have the reader version installed.
just rotate the control. put the control in a panel and rotate the panel or something.
I don't suppose you could put controls on the PDF that prevent saving and printing?

Categories