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

Free Support Forum - aspose.com

How to retain formatting of PDF document while replacing it's text

Hi,

I am trying to change the text of PDF files using TextFragment.
textFragment.Text = “new text”;

Text gets replaced but I also want to retain its formatting like if the original text is Bold , new text should also be in bold. ( Or any other such cases like color and text styles. )


Hi Ruchi,


Thanks for contacting support.

In order to accomplish your requirement, you need to perform following steps.

  1. First search the particular text string which you need to replace.
  2. Get the current formatting information of TextFragment.
  3. Replace text string and use previously obtained formatting information for newly replaced string.

In case you still face any issue, please share the resource PDF file.
Hii
Thats what I wanted to ask.
How to get and set current textFragment formatting information?
If you can provide me some code snippet, it would be a great help.

Hi Ruchi,


Please visit the following link for required information on

Hii,

I checked the links. This links contains information about setting the formatting.
But How to get this formatting information first ?
If I use same properties to get the information before replacing text, it says these properties lacks the get accessors.

Hi Ruchi,


Thanks for your feedback, In first link we are getting and printing text formatting of TextFragment. You may store the properties in some variables and can apply these to replaced text as stated in second link.

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

float font=textFragment.TextState.FontSize;<o:p></o:p>

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

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

textFragment.TextState.FontSize = font;<o:p></o:p>

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


Please feel free to contact us for any further assistance.


Best Regards,

Font and FontSize properties are having getter and setter both , But FontStyle is having only setter.

Similarly forgroundColor property is having getter and setter both but backgroundColor have only setter.
Underline is also having only setter.
Is this done purposefully or you may fix this issue in next version.

1 Like

ruchi.eck:
But FontStyle is having only setter.
Hi Ruchi,

Thanks for sharing the details.

I have logged the above stated requirement as PDFNEWNET-38013 in our issue tracking system.
ruchi.eck:
backgroundColor have only setter.
This requirement is logged as PDFNEWNET-38011.
ruchi.eck:
Underline is also having only setter.
I have separately logged it as PDFNEWNET-38012 in our issue tracking system.
ruchi.eck:
Is this done purposefully or you may fix this issue in next version.
As we just have logged these requirements, so currently we cannot confirm the timelines by which they will be implemented but as soon as we have made some definite progress towards their implementation, we will let you know.

Please be patient and spare us little time.

The issues you have found earlier (filed as PDFNET-38012) have been fixed in Aspose.PDF for .NET 18.10.

The issues you have found earlier (filed as PDFNET-38011) have been fixed in Aspose.PDF for .NET 19.5.

The issues you have found earlier (filed as PDFNET-38013) have been fixed in Aspose.PDF for .NET 21.3.