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

Free Support Forum - aspose.com

Retain Text Formats like Underline,Strikeout,Text Alignment while replacing Text in PDF

Hello,
We have a PDF with set of KeyWords. The KeyWords have formatting like Underline,Strikeout,Highlight,Alignment defined.

This PDF is created by performing a saveas in MS Word.

ASPOSE PDF(Java):
1.Get the Keywords using TextFragmentAbsorber
2.Replace the KeyWords actual Value
3.Save to new file

Issues:
1.Under Line is not applied to the new Value (Eg: KEY=#!Key1 VALUE=This is a Test Replacement RESULT:This is a Test Replacement is replace. ISSUE: only “This i” is underlined)
2.Same as above for Strikeout,Highlight
3.In Word say a Key is Center Aligned, But while replacing this is not considered.

Is there a way to acheive this by retaining all the formats from KeyWords?

@sarvanan.murthi.ext,
We have tried your scenario with the latest version 17.9 of Aspose.Pdf for .NET API and could replicate the said issues in our environment. Please download and try the latest version 17.9 and if this does not help, then kindly send us the complete details of the use case including source PDF and code. We will investigate and share our findings with you.

[C#]

string dataDir = @"C:\Pdf\test355\";   
string[] arr1 = new string[] { "line", "through", "aligned" };
// Open document
Document pdfDocument = new Document(dataDir + "Input.pdf");
foreach (string keyword in arr1)
{
    // Create TextAbsorber object to find all instances of the input search phrase
    TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber(keyword);

    // Accept the absorber for all the pages
    pdfDocument.Pages.Accept(textFragmentAbsorber);
    // Get the extracted text fragments
    TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
    // Loop through the fragments
    foreach (TextFragment textFragment in textFragmentCollection)
    {
        // Update text and other properties
        textFragment.Text = textFragment.Text + "Updated";
    }
}
// Save resulting PDF document.
pdfDocument.Save(dataDir + "ReplaceTextAll_out.pdf");

Input PDF: Input.pdf (89.1 KB)
Output PDF: ReplaceTextAll_out.pdf (108.0 KB)

Hi Imran,

We have tried with Aspose.Pdf for .NET API (17.9) and JAVA API (17.8) both. The said issues exists.

I will share the actual pdf, word doc(that we used to create PDF) and source code for further analysis.
Aspose_Replace.zip (220.9 KB)

@sarvanan.murthi.ext,
We managed to replicate the said issue in our environment. It has logged for both .NET and Java platforms under the ticket IDs PDFNET-43430 and PDFJAVA-37119 in our bug tracking system. We have linked your post to these tickets and will keep you informed regarding any available updates.

Hello Aspose Team,

is there any update on PDFJAVA-37119?

@sarvanan.murthi.ext,

The linked ticket ID PDFJAVA-37119 is pending for the analysis and not resolved yet. We will investigate as per the development schedules and let you know once a significant progress has been made in this regard.

Hello Aspose Team,

is there any update on PDFJAVA-37119?

@sarvanan.murthi.ext

Thanks for your inquiry.

I am afraid that earlier logged ticket is not yet resolved. However, please note that we have already raised the issue priority in order to escalate investigation process. As soon as we have some definite updates regarding resolution of the logged issue, we will let you know. Please be patient and spare us little time.

We are sorry for the inconvenience.

Hello Aspose Team,

is there any update on PDFJAVA-37119?

@sarvanan.murthi.ext

I am sorry to share that we cannot provide any definite update regarding issue resolution because of long queue of pending issues. However, as soon as we make some significant progress towards issue resolution, we will surely let you know. Please be patient and spare us little time.

We are sorry for the inconvenience.

Hello Aspose Team,

is there any update on PDFJAVA-37119?

@sarvanan.murthi.ext

Thanks for your inquiry.

I regret to share that due to large number of pending issues in the queue, we will not be able to resolve your issue in this year because it was logged under free support model and has low priority. It will be resolved on first come first serve basis. However, you can always raise the priority of your issue by checking and considering paid support model where issues are resolved on urgent basis. We will surely inform you in case we have some further updates regarding issue resolution. Please spare us little time.

We are sorry for the inconvenience.