Text insertion

Hi,

Can Aspose PDF insert text at and after a certain field(Field1) name without causing overlap to the field(Field2) after?

For example:
“test1” (Field1)
“test2” (inserted text)
“test3” (inserted text) etc…
Field2

Thanks
Steve

@hsiungst

Would you kindly share a sample PDF for our reference so that we can check what type of fields it has and how can text be added before and after them. We will then share our feedback with you accordingly.

TestDoc2.pdf (267.9 KB)
Hey Ali, here’s an example file … the field Member_Full_Name should be a singular field and then we add other names after the Member_Full_Name omitting the need for the fields IL_Join1,2 & 3_Full_Name.

Thanks
Steve

@hsiungst

As per our understandings, you need to replace the placeholders with some values. Please check following code snippet in order to do that. In case your requirements are different, please let us know about your feedback:

var doc = new Aspose.Pdf.Document(dataDir + "TestDoc2.pdf");

TextFragmentAbsorber absorber = new TextFragmentAbsorber(@"«Member_Full_Name»", new TextSearchOptions(true));
absorber.TextReplaceOptions = new TextReplaceOptions(TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation);
absorber.TextReplaceOptions.ReplaceScope = TextReplaceOptions.Scope.REPLACE_ALL;
doc.Pages.Accept(absorber);
doc.Pages[1].Accept(absorber);
foreach(TextFragment textfragment in absorber.TextFragments)
{
 textfragment.Text = "Aspose Test Name";
}
doc.Save(dataDir + @"FindAndReplace_out.pdf");

Ali, thanks for your reply. We not only would like to replace the placeholder with text but also add text after the place holder like so:

<<Member_Full_Name>> - replaced text is “Aspose Test Name”
“Aspose Test Name2”
“Aspose Test Name3”
etc. etc. this action should cause the next placeholder to slide down

<<Member_Address>> placeholder example

Can this be achieved by using Spire PDF?

Thanks
Steve

@hsiungst

We tried to achieve your requirements using following code snippet but noticed that New Line was not detected by the API and text did not break which seemed like a bug.

var doc = new Aspose.Pdf.Document(dataDir + "TestDoc2.pdf");

TextFragmentAbsorber absorber = new TextFragmentAbsorber(@"«Member_Full_Name»", new TextSearchOptions(true));
absorber.TextReplaceOptions = new TextReplaceOptions(TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation);
absorber.TextReplaceOptions.ReplaceScope = TextReplaceOptions.Scope.REPLACE_ALL;
doc.Pages.Accept(absorber);
doc.Pages[1].Accept(absorber);
foreach(TextFragment textfragment in absorber.TextFragments)
{
 textfragment.Text = "Aspose Test Name\nNew Aspose Test Name";
}
doc.Save(dataDir + @"FindAndReplace_out.pdf");

We have logged an issue as PDFNET-48670 in our issue tracking system for it. We will further look into its details and keep you informed with the status of its rectification. Please be patient and spare us some time.

We are sorry for the inconvenience.

Yes, I tried the same thing using “\r\n” and it did not break either.

Thanks for checking
Steve

@hsiungst

Thanks for the acknowledgement.

We also had tried using Environment.NewLine but could not get success. Nevertheless, we will inform you as soon as we have additional updates in this regard.