Hi there, I’m using the Aspose.pdf 11.4.
I got a problem in replacing the text in the existing pdf.
Here is my code:
Document pdfDoc = new Document();
Aspose.Pdf.Page pdfPage = pdfDoc.Pages.Add();
Aspose.Pdf.Heading heading = new Aspose.Pdf.Heading(1);
heading.TextState.Font = FontRepository.FindFont(“Trade Gothic LT Com Bold”);
heading.TextState.FontSize = 15;
//heading.TextState.FontStyle = FontStyles.Bold;
//heading.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);
heading.Text = “List 1”;
heading.Segments.Add(new TextSegment(“List 4”));
var heading2 = new TextFragment();
heading2.Text = “List 2”;
heading2.TextState.Font = FontRepository.FindFont(“Trade Gothic LT Com Bold”);
heading2.TextState.FontSize = 15;
heading2.TextState.FontStyle = FontStyles.Bold;
heading2.TextState.ForegroundColor = Aspose.Pdf.Color.FromRgb(System.Drawing.Color.Red);
pdfPage.Paragraphs.Add(heading);
pdfPage.Paragraphs.Add(heading2);
pdfDoc.Save(“c:/pdftest/replace.pdf”);
TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(“List”);
//accept the absorber for all the pages
pdfDoc.Pages.Accept(textFragmentAbsorber);
//get the extracted text fragments
TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
//loop through the fragments
foreach (TextFragment t in textFragmentCollection)
{
t.Text = “Proposal test”;
}
pdfDoc.Save(“c:/replace.pdf”);
Thanks