Display PDF preview in WPF and search for a phrase - c#

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?

Related

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

How would you create a page like WP's Mail app's Compose screen?

I'm new to WP dev (and pretty much C# and Silverlight in general) and I've been playing with Textboxes. I found pretty quickly that you can't really scroll a TextBox control.
I've seen some solutions to this on various blogs and StackOverflow posts, and the most popular one seems to be to embed the TextBox in a ScrollViewer, then use some code to make the current input line always visible, like this:
scrollViewer.ScrollToVerticalOffset(textBox.ActualHeight);
This works okay if you have a relatively small TextBox, but if you want to make one that takes up quite a bit of space, you run into problems where the keyboard covers up the bottom section, you can't scroll to the top unless you manually move the cursor up there, etc.
Now the Compose page of the Mail application seems to do this perfectly: a nice big space for text entry where the keyboard never blocks the input, you can freely scroll through the entire pane, it just works really. I've tried various combinations of scrollviewers and textboxes but I haven't had any success in matching its behavior.
Any help?
The default apps are not written in C# using controls accessible in SDK or on the net.
Replication of mail viewer and composer has been tried before rather un-successfully. (Based on similar posts of AppHub - old WP7 forum)

Showing multiple PDF Files in WebBrowser control (Windows Form)

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.

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.

Possible to render html in a compact edition mobile 6 phone form?

I am wondering does anyone know if it is possible to render html in a mobile 6 form? The only way I can think that may work is the internal web browser control.
I am wondering is there a better way? I am thinking if I go the path of web browser control I will have to generate an html file then insert the code I want into this file.
I need something like this because I am pulling in some text that can possibly be formatted with html stuff such as font weight.
A Browser Control is really the only way (unless you want to parse the HTML yourself and turn it into rich text for an RTF control, or worse, manually handle it all yourself).
As people have said you do need 2 controls, but it might be possible to hide the regular textbox (maybe behind the browser control) will still leaving it editable.
In this case although it would be controlled underneath with code like <b>mytext</b>, the user would never see that giving them some illusion of a WYSIWYG editor (though I can already imagine a few problems you might come into attempting this)
I have written an HTML edit control for .NET.
It doesn't currently support Windows Mobile: but I have Windows Mobile development experience myself, and I might be able to port it to the Compact Framework, if you would be willing to pay for that, as explained in the Developing New Functionality section.

Categories