Foxit Quick PDF Library

Replace text in PDF

Currently it is only possible to replace simple text that has not been encoded using Foxit Quick PDF Library using the scripting feature which uses Foxit Quick PDF Library behind the scenes.

The function that lets you replace text is the ReplaceTag function. Basically, it is possible to replace some text in a PDF file if the text is not encoded. Foxit Quick PDF Library can create PDFs without encoded text, so it’s possible to use the ReplaceTag function with some PDFs that were created using our PDF SDK. However, the big catch is that you can only replace words of the same length. So you can replace Moby with Mary, but you can’t replace Moby with Jessica.

How does the ReplaceTag function work?

The ReplaceTag function simply replaces text in the page’s content stream, so for most documents it wouldn’t have any effect. For some simple documents it might be able to replace content, but it really depends on how the PDF was constructed. Essentially it’s the same as doing:

DPL.CombineContentStreams();
string content = DPL.GetContentStreamToString();
DPL.SetPageContentFromString(content.Replace("Moby", "Mary"));

If you created a PDF using Foxit Quick PDF Library and a standard font then the ReplaceTag function should work – however, for PDFs created with tools that do subsetted fonts or even kerning (where words will be split up) then the search text probably won’t be in the content in a simple format.

So in short, the ReplaceTag function will only work in some limited scenarios and isn’t a function that you can rely on for searching and replacing text.

This article refers to a deprecated product. If you are looking for support for Foxit PDF SDK, please click here.

Updated on May 16, 2022

Was this article helpful?
Thanks for your feedback. If you have a comment on how to improve the article, you can write it here: