Transparent text in existing PDFs

Hello,


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);
document.Pages.Accept(textFragmentAbsorber);

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

document.Save(path-to-new-file);

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

Thank-you.

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.

…<o:p></o:p>

....

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

doc.Pages.Accept(textFragmentAbsorber);

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,