4

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:

  1. 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.

  1. 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

  1. 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.

  1. 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.

  1. 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?

Community
  • 1
  • 1
Sergey Belikov
  • 420
  • 3
  • 14
  • Why do you want to see preview inside wpf window in first place? Do you think to make better PDF viewer than the one your customer has installed? E.g. if you generate reports in pdf format, then just open it with default operation system pdf-handler, it comes with search, printing and alot more options. You can offer one as a part of installation option (adobe acrobat reader?). – Sinatr Sep 23 '15 at 12:40
  • It is actually a Word add-in, that displays other documents in a TaskPane. And Acrobat reader does not support phrase search via command-line arguments, so we still have to emulate keystrokes to use it. – Sergey Belikov Sep 24 '15 at 08:30
  • Try MoonPDF Panel: http://www.codeproject.com/Articles/579878/MoonPdfPanel-A-WPF-based-PDF-viewer-control – VahidN Sep 24 '15 at 09:17
  • MoonPDF display pdf as images. No text highlight and copy paste. – Sergey Belikov Sep 25 '15 at 17:37
  • For those who interested, we have stopped on Patagames viewer by now: http://pdfium.patagames.com/ – Sergey Belikov Feb 18 '16 at 14:05

0 Answers0