views:

2697

answers:

2

Hi there,

.Net contains a nice control called DocumentViewer. it also offers a subcontrol for finding text in the loaded document (that's at least what it is supposed to do).

When inserting FixedPage's objects as document source for the DocumentViewer, the find-functionality just does not find anything. Not even single letters. I haven't tried FlowDocument's yet, as the documentation for DocumentViewer is not that useful and the resources on the net are not actually existing, I now want to ask the stackoverflow community:

What does it need to get the Find-Function of the WPF DocumentViewer working with FixedPage documents?

[btw, I don't use custom ControlTemplates for DocumentViewer]

+1  A: 

I had trouble with searching text in richtextbox, it was too slow. What I did was crunch the xaml every time I wanted to search. I improved several orders of magnitude.

It's a big workaround based in a part of the Chris Anderson's book.

Cheers

Artur Carvalho
+3  A: 

I had this same problem with FixedDocuments. If you convert your FixedDocument to an XPS document then it works fine.

Example of creating an XPS Document in memory from a FixedDocument then displaying in a DocumentViewer.

XpsDocument YourXPSDoc;
ms = new MemoryStream();
DocumentUri = new Uri("pack://document.xps");
p = Package.Open(ms, FileMode.Create, FileAccess.ReadWrite);
PackageStore.AddPackage(DocumentUri, p);
YourXpsDoc = new XpsDocument(p, CompressionOption.NotCompressed, DocumentUri.AbsoluteUri);

XpsDocumentWriter dw = XpsDocument.CreateXpsDocumentWriter(YourXpsDoc);
dw.Write(YourFixedDoc);
FixedDocumentSequence fixedDocumentSequence = YourXpsDoc.GetFixedDocumentSequence();
if (fixedDocumentSequence == null)
{
    return;
}
documentViewer.Document = fixedDocumentSequence;
+1 worked perfectly for me
Steve Greatrex