# Can I replace text while keeping the same font?

Q: Can I replace text while keeping the same font?

I can search and replace the text, but I have an problem with the font
not showing properly when I try to use the original pdf's embedded
font.

Is there anything I need to do to render the font correctly?

elem_text=element.GetTextString()
if instr(elem_text,"old",1) then 'Search string found
Dim gs As GState = element.GetGState()
Dim current_font As PDF.Font = gs.GetFont 'Grab the font
used for the orig element
Dim current_font_size As Double = gs.GetFontSize 'Grab the
fontsize used for the orig element

new_str = Replace(orig_str, srch_str, repl_str, 1, -1,
CompareMethod.Text)
tm = element.GetTextMatrix()
Dim itr As CharIterator = element.GetCharIterator()
tm.m_h += itr.Current.x
tm.m_v -= itr.Current.y

Dim ex As ElementBuilder = New ElementBuilder
' Note for this orig pdf, current_font is an embedded font "Arial
+2"
element = ex.CreateTextRun(new_str, current_font,
current_font_size)
element.UpdateTextMetrics()
element.SetTextMatrix(tm)
end if
writer.WriteElement(element) '<<<<<< Does not display properly when
Current_font is Embedded
-------
A: Modifying text while keeping the old font can be tricky (please
search for "How do I edit PDF text" in this forum. The problem is that
the font may use custom encoding or may be missing required glyphs (if
the font is subsetted). Usually it is much simpler to use a new font