We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Transparent text in existing PDFs


I am trying to remove text from an existing PDF, whilst maintaining the positioning of the surrounding text. Because of this, simply setting textFragment.Text = “” is not a viable solution. I have tried a couple of things: replacing the text with a set number of spaces gave varying degrees of success - depending on exactly what text was surrounding the fragment - and setting the text fragment colour to Color.Transparent, which instead sets the text colour to white.

The code I am currently using is as follows:

Document document = new Document(path-to-file);

TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(regularExpression);
textFragmentAbsorber.TextSearchOptions = new TextSearchOptions(true);

foreach (TextFragment tf in textFragmentAbsorber.TextFragments) {
tf.TextState.ForegroundColor = Color.Transparent;


Is what I am trying to accomplish not actually possible, or is there something I am missing?


Hi Chris,

Thanks for your inquiry. Please check following code snippet, replacing searched text with a string of empty characters of equal length. Hopefully it will help you to accomplish the task. However if there is any difference in your requirement and my understanding then please share some sample Input and output PDF document to describe your requirements.



textFragmentAbsorber.TextReplaceOptions.ReplaceAdjustmentAction = TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation;


foreach (TextFragment textFragment in textFragmentAbsorber.TextFragments)


string reptext = "";

int length = textFragment.Text.Length;

for (int i = 1; i <= length; i++)

reptext = reptext + " ";

textFragment.Text = reptext;




Please feel free to contact us for any further assistance.

Best Regards,