I am using the TextFragmentAbsorber to iterate over the text fragments contained in a PDF document, and I would like to deleted selected TextFragment objects. How can I do this? The TextFragmentCollection class does not seem to have a Remove() option.
Hi Avi,
Please elaborate and explain what you mean by “replace the fragment with blank instance” (I examined the links, but they don’t have any examples of blank instances).
Hi Avi,
as PDFNEWNET-39171 in our issue tracking system. We will further
look into the details of this problem and will keep you updated on the status
of correction. Please be patient and spare us little time. We are sorry for
this inconvenience.
// Load source PDF file<o:p></o:p>
Document doc = new Document("c:/pdftest/42441893 (1).pdf");
// Create TextFragment Absorber object with regular expression
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("organisationer");
textFragmentAbsorber.TextReplaceOptions.ReplaceAdjustmentAction = TextReplaceOptions.ReplaceAdjustment.AdjustSpaceWidth;
doc.Pages.Accept(textFragmentAbsorber);
// Replace each TextFragment
foreach (TextFragment textFragment in textFragmentAbsorber.TextFragments)
{
// Set font of text fragment being replaced
textFragment.TextState.Font = FontRepository.FindFont("Arial");
// Set font size
textFragment.TextState.FontSize = 12;
textFragment.TextState.ForegroundColor = Aspose.Pdf.Color.Navy;
// Replace the text with larger string than placeholder
textFragment.Text = "";
}
// Save resultant PDF
doc.Save(“c:/pdftest/TextRemove.pdf”);
Dear Nayyer,
Hi Avi,ashmid_a:2] Indeed, as you note, after deleting selected characters, the rest of the text is completely misarranged. Worse, many of the text fields become doubled (e.g. fragments that were "2" are now "22"), and others have disappeared from the page completely. Please do notify us when this has been resolved.
Concerning your initial inquiry, we would like to share with you that now you can Remove All Text from PDF document using TextFragmentAbsorber which is a faster way to remove text. Please use the linked example with the latest version of the API and in case you need further information, please feel free to let us know.