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

Free Support Forum - aspose.com

Text format being cleared out when replacing

I am opening up an existing PDF document and replacing token text with database driven values. Everything is working except the formatting of the text is not being preserved. For example if the text is bold and I replace it the bold is lost. Throughout the document there are different fonts and weights so I don’t know at runtime what the style should be but would like it to just remain however it was and just replace the text. Here is the method I’ve got that does the actual replacement.


Should I be doing something more?

I pass in the PDF document I’m working with, the text I want to replace and the new text…

public static void replaceText(Document document, string findText, string replaceText)
{
TextFragmentAbsorber fragment = new TextFragmentAbsorber(findText);
document.Pages.Accept(fragment);
TextFragmentCollection fragmentCollection = fragment.TextFragments;

foreach (TextFragment textFragment in fragmentCollection)
{
textFragment.Text = replaceText;
}
}

Hi,


Thanks for using our products.

I have tested the scenario with Aspose.Pdf for .NET 8.5.0, where I have used one of my sample PDF files and I am unable to notice any problem. Can you please share the PDF files causing this problem so that we can test the scenario at our end. We are sorry for your inconvenience.

Attached is the PDF template I’m using and here are the tokens I’m replacing with the method posted before.


//Find all the first name tokens
replaceText(pdfDocument, “FirstName”, firstName);
replaceText(pdfDocument, “LastName”, lastName);
replaceText(pdfDocument, “ProfileDate”, DateTime.Now.ToShortDateString());

if (FemaleTF)
{
replaceText(pdfDocument, @"%he", “she”);
replaceText(pdfDocument, @"%He", “She”);
replaceText(pdfDocument, @"%him", “her”);
replaceText(pdfDocument, @"%Him", “Her”);
replaceText(pdfDocument, @"%his", “her”);
replaceText(pdfDocument, @"%His", “Her”);
replaceText(pdfDocument, @"%himself", “herself”);
replaceText(pdfDocument, @"%Himself", “Herself”);
}
else
replaceText(pdfDocument, @"%", “”);

Hi Bradley,


Thanks for sharing your source document. I’ve tested the scenario with Aspose.Pdf for .NET 8.5.0 and I’m afraid I’m unable to notice the formatting issue. i.e. word style is preserved. Can you please download and try latest version of Aspose.Pdf for .Net. Hopefully it will resolve the issue. If issue persist then please share your working environment. So we will try to replicate the issue accordingly.

Please feel free to contact us for any further assistance.

Best Regards,

Here is an example output file. I’ve highlighted and added comments on page 2 and 4 so you can see what is going on. I’m using the newest version already.

Hi Bradley,

Thanks for your feedback. It seems you are using 8.4 and we’ve tested the scenario with 8.5. Can you please give a try to 8.5 and share the results? So we will investigate it further.

Thanks for your cooperation.

Best Regards,

I updated to 8.5 and still having the same issues. Source file is the same and output appears to be the same as well but I have attached and highlighted.


When I remove the “%” from the pronouns or replace the FirstName with the data driven value the font style is lost and extra spaces are sometime included.

Hi Bradley,


Thanks for your feedback. After initial investigation, we’ve logged an investigation ticket as PDFNEWNET-36013 for further investigation and resolution. We will update you as soon as it’s resolved.

Moreover, I’ve tested the scenario over Win 7 64 bit, VS2010 and Aspose.Pdf for .NET 4.0 .NET Framework dll. It would help to resolve the issue if you please also share your environment details.

Best Regards,

Okay just keep me informed. I am using the same operating system and configuration.

Hi Bradely,


Thanks for your feedback. As soon as we have made some progress towards its resolution, we will update you within this forum thread.

Thanks for your patience and cooperation.

Best Regards,

Will you provide an estimate on when I can expect a resolution on this issue? I’m going to need to get a fix pretty soon or switch to a different component provider.


Thanks.

brad

Hi Bradley,


Thanks for your patience.<o:p></o:p>

The development team has been busy resolving other priority issues and I am afraid the issue reported earlier is not yet resolved. Nevertheless, I have requested the team to share the ETA regarding its resolution. As soon as we have some definite updates regarding its resolution, we would be more than happy to update you with the status of correction. Please be patient and spare us little more time.

Also please note that you have reported issue under normal/free support forum and as a normal rule of practice, issues are resolved in first come and first serve basis; but the problems logged/reported under Enterprise or Priority support model, have high precedence in terms of resolution, as compare to issues under normal/free support model. We are really sorry for this inconvenience.

Can I get an update on PDFNEWNET-36013 please?


Thanks.

brad

Hi Bradley,


Thanks for your patience.

The development team has been still busy resolving other priority issues and I am afraid the above stated problem is not yet resolved. Nevertheless, I have again intimated the development team to share the possible ETA. As soon as we have the required information, we would be more than happy to update you with the status of correction.

The issues you have found earlier (filed as PDFNEWNET-36013) have been fixed in Aspose.Pdf for .NET 9.7.0.


This message was posted using Notification2Forum from Downloads module by Aspose Notifier.