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

Free Support Forum - aspose.com

Underline not being removed .NET

This is for Aspose.NET, latest version. Using the pdfContentEditor, when trying to remove text from a PDF, the underline still stays there even though the text is removed.

Is there a way to remove the underline from text?

@coderandom1

Thank you for contacting support.

Would you please share source and generated files along with narrowed down code snippet so that we may try to reproduce and investigate it in our environment.

Code snippet:

textFragment.Text = CreateReplacementString(textFragment.TextState.FontSize, textFragment.Rectangle.Width);
textFragment.TextState.ForegroundColor = Color.Black;
textFragment.TextState.Underline = false;

private string CreateReplacementString(float fontSize, double weightString)
{
    char block = '█';
    double weightBlockOnePoint = 0.7085;
    double weightChar = fontSize * weightBlockOnePoint;
    return new string(block, (int)(weightString / weightChar));
}

Files:
phone_input.pdf (23.3 KB)
phone_output.pdf (48.0 KB)

@coderandom1

Thank you for sharing requested data.

Please share SSCCE code which also specify how are you searching required text and then removing it so that we may proceed to investigate it further and assist you accordingly.

We changed the code a bit, but the result is the same.

Document pdfDocument = new Document(inputStream);

TextAbsorber textAbsorber = new TextAbsorber();
pdfDocument.Pages.Accept(textAbsorber);
string extractedText = textAbsorber.Text;

string regex = @"\b(?:(?:(?:[!#$%&'*+\-/=?^_`{|}~\w])|(?:[!#$%&'*+\-/=?^_`{|}~\w][!#$%&'*+\-/=?^_`{|}~\.\w]{0,}[!#$%&'*+\-/=?^_`{|}~\w]))@\w+(?:[-.]\w+)*\.\w+(?:[-.]\w+)*)\b";
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(regex, new TextSearchOptions(true));
textFragmentAbsorber.TextReplaceOptions.ReplaceAdjustmentAction = TextReplaceOptions.ReplaceAdjustment.None;
pdfDocument.Pages.Accept(textFragmentAbsorber);

foreach (TextFragment textFragment in textFragmentAbsorber.TextFragments)
{
	char space = ' ';
	double rectangleWeight = textFragment.Rectangle.Width;
	textFragment.Text = space.ToString();
	textFragment.Text = new string(space, (int)(rectangleWeight / textFragment.Rectangle.Width) + 1);
	textFragment.TextState.BackgroundColor = Color.Black;
	textFragment.TextState.Underline = false;
}

pdfDocument.Save(outputStream);

@coderandom1

Thank you for sharing requested data.

We have been able to reproduce the issue in our environment. A ticket with ID PDFNET-46063 has been logged in our issue management system for further investigation and resolution. The ticket ID has been linked with this thread so that you will receive notification as soon as the ticket is resolved.

We are sorry for the inconvenience.