I like DocumentViewer for display of an XPS document in a WPF application. But I also need to redact the XPS document. I have found stand alone applications (.exe) for redacting XPS. What I need is a WPF control for view and redaction of XPS. Or an extension to DocumentViewer for redaction. The redaction must actually remove the data and not just hide it (this is for a litigation application). Does anyone know of way to view and redact XPS in WPF?
Asked
Active
Viewed 921 times
4
-
It could be possible using a custom paginator as at that point everything has been turned into a visual. 1) Find the text to redacted, create a black shape over the text, and then flatten the page to a single image. The only part that I'm not certain on and would have to check tomorrow is how accurately you could select paragraph/run/glyphs and redact them. Also not certain if you would be able select any non-redacted text afterwards. – Dennis Feb 28 '12 at 00:13
-
Don't forget the part "must actually remove the data". There can be no unredact. – paparazzo Feb 28 '12 at 13:21
-
That is my point about flattening the visuals, the text visual under the redaction block will be destroyed. – Dennis Feb 28 '12 at 15:47
-
@DennisRoche If you will post an answer I will vote it up or accept it. The current only answer is not as good as your comments. – paparazzo Mar 05 '12 at 13:40
-
I was hoping that my comments would lead you in the right direction, enough to figure out a solution. I can post several articles and background information on Paginators that will help, however I don't have time (and haven't for the last 7 days) to write a proper answer. – Dennis Mar 05 '12 at 16:50
2 Answers
3
With a custom DocumentPaginator
you can control how each element of the document is printed.
If you can identify the text ranges you want to redact then you can replace the glyphs with a black visual and not add the text range to the final document.
...
Hmm. As I typed the above it really sounds a bit complex when there are simpler solutions.
- Read the XPS document, convert it to a FlowDocument.
- Allow the user to select text ranges to redact.
- Replace* the selected text with the ████████████████ character (U+2588, Full Block).
- Convert the document back to XPS and print.
* As you replaced the original text, it will not be available in copy/paste actions.
There are plenty of tutorials on how to each the above steps separately. Let me know if you need any additional help.

Dennis
- 20,275
- 4
- 64
- 80
1
If my mind don't lie, you can't edit XPS directly, but you can create WPF representation of document, edit it and print to new XPS file.

Arman Hayots
- 2,459
- 6
- 29
- 53
-
1Arman is right... even you can "add text" (not recommended) to the XPS, it does not preserves important stuff like Margins and PageLength, so WPF does not reformats the document. Keep in mind that XPS documents are almost "written in stone", already formatted and ready to be printed. – NestorArturo Mar 05 '12 at 15:05