-->

Question Marks in XPS Document

2019-08-07 11:58发布

问题:

I was playing around with XPS in C# and used this example as a starting point: https://code.msdn.microsoft.com/windowsdesktop/How-to-Edit-XPS-file-in-WPF-724ef6fb

I modified the example a bit and created a search and replace application for XPS documents.

The output doesn't look very well:

Copy and paste the question marks to an editor works well and gives me the correct characters.

Now I've found out that when characters are not in the source XPS and new characters are in the target XPS, they can not be found in the font (found this explanation here: https://stackoverflow.com/a/28236296/2058139).

The essence of the problem lies in the use of ODTTF fonts in XPS document. The ODTTF is an obfuscated subsetted font based on the fonts used in the original document. This means that you cannot use for the replacement any character that wasn't in the original document.

Any solution for this?

回答1:

The good news: You've accurately diagnosed your problem.

The bad news: The embedded ODTTF truly does not have the required glyphs for your new text. You will need to embed a new font. It is an awful hack, but it may be possible to determine the original font that was used. If that same font happens to be installed, you can redo the font embedding process, generating a new ODTTF that contains the glyphs you need. Needless to say, this is a terrible hack that can fail badly at several points. How you handle the situation will be highly dependent on the specific use cases for your application.