I'm trying to replace text in XPS documents and I've got nowhere.
What we're trying to do is replace our old word templates that have bookmarks as placeholders; we use vb6 to replace the text where the bookmarks are. This is so users can create generic documents and merge them with our data from our database.

We want to replace this as honestly the current solution isn't that good, but does work, so it's not all bad. I've created an XPS document with bookmarks, can't seem to figure out what makes a bookmark a bookmark in XPS. But really all we would need would be a placeholder like <Address> or <Name> or something and then replace that text with data.

Can anyone help or at least point me in the right direction


Re: XML Paper Specification (XPS) Replace text in XPS documents


basicly you could read the xps-markup of the FixedPage-PackageParts using OPC, then use a XML DOM to read the elements and change the attributes like text and then write back that modified xps-markup to the FixedPage-PackagePart (send an email if you need an example how to read/write those FixedPage-parts)

Just have a look at the "XML Paper Specification 1.0" to find out how a hyperlink (or if it's simple textoutput -> Glyph) is defined in XPS, so you know which attributes you have to change then...

But remember that XPS is a fixed document, means it doesn't recalculate it's layout like doing in a WPF flow-document... so changing/replacing text could cause "some trouble" in layout... (c;

Re: XML Paper Specification (XPS) Replace text in XPS documents



Is it possible to remove/add glyphs object at runtime in fixedpage.

Atually I am trying to replace one glyphs with another at runtime to replace the placeholders put in xps document.

For example

Mr. XX has to pay $ <TaxableAmount></TaxableAmount> to US government.

Here, at runtime I want to find out <TaxableAmount> tag and replace it with 1000.

Since XPS is fixed format document if this actual content (in case of string) is big how to achieve pagination

Any sample would be much appreciated.

Re: XML Paper Specification (XPS) Replace text in XPS documents


Watch out for font sub setting and font protection:
  • If the font in the xps is a subset, the glyphs you are trying to use might not be available.
  • If the font is obfuscated/protected, you might not be allowed to change/add text.

oasisman: I have a solution for text search & replace (via a custom c++ library, and also via a custom application), if you're interested in trying one of these, contact me directly via e-mail.


Re: XML Paper Specification (XPS) Replace text in XPS documents


Thanks Nixps,

Can you please share the sample so that I can play around to see it serves the purpose

Re: XML Paper Specification (XPS) Replace text in XPS documents

Feng Yuan

If you define your template in XAML, which is a super-set of XPS markup, and then generate XPS from it, WPF will take care of everything for you.

If you define your template in XPS, but use WPF to process it, WPF can take care of font issue to have the right glyphs embedded in the document.

Otherwise, here are some consideration:

1) Embed the whole font, or at least make sure you have all necessary glyphs which may be needed later.

2) Seperate out the place holders to be a seperate Glyphs elements.

3) Leave enough space for the place holders, so nothing needs to be moved around.

4) If the replacement has one-to-one UNICODE to glyph indices mapping and you do not have special needs for glyph positioning, just provide the UnicodeString.

5) Consider using bitmaps for place holders/replacements.

Feng Yuan

Re: XML Paper Specification (XPS) Replace text in XPS documents


Hi all,

Can u help me to create bookmark in XPS file using vb.net.

it is urgent...