Q:
We are editing a pre-existing PDF (generated via Reporting Services)
which we would like to embed a font into - effectively replacing the
reference to the font that was used previously with the new embedded
font. Do you have a code snippet where a font is replaced within an
existing document?
---
A:
In PDF format it is not trivial to change font associated with a text
run. The problem is that fonts may be using different encodings so
switching from one font to another could produce garbage output. You
can change font associated with a given 'text run' only if you are
absolutely sure that font encodings match and that all required glyphs
are available in the new font.
To go around this issue, instead of modifying font on the existing
text run, you can replace the entire text run with a new run (created
using ElementBuilder, see ElementEdti sample project) using the new
font and Unicode string returned from old_element.GetTextString().