Remove Document Footer unicode text dynamically WPF c#


#1

Hi Aspose Team,

We are using Apsoe.Words .NET for our application developed using C# WPF technology.

Requirement: To Replace document Footer specific part of Text dynamically.
Here complete text is dynamic (coming from Data Base) hard-coding not possible.

Problem:

I am facing issue in Replacing the Footer text as Unicode’s or special characters are present in the string.
Footer.Range.Rplace( ) method does is not working here. I am trying to make these Unicode as null. But not working.
Below is my sample code for your reference:
Code I am using:

Document docFooterRplace = new Document(JobFolderPath + filename);
HeaderFooterCollection headersFooters = docFooterRplace.FirstSection.HeadersFooters;
HeaderFooter footer = headersFooters[Aspose.Words.HeaderFooterType.FooterPrimary];
FindReplaceOptions options = new FindReplaceOptions
{
MatchCase = false,
FindWholeWordsOnly = false
};

footer.Range.Replace(new System.Text.RegularExpressions.Regex(@"[^\u0014-\u007E]"), “”, options);

docFooterRplace.Save(JobFolderPath + “\HeaderFooter.ReplaceText.doc”);

Attached code line shows the codes or special characters with Red boxes. I need only text to come and no Codes or special characters. So Replace method works.

FooterUnicodes.png (13.1 KB)

Request you to please provide some solution on this.

Please let me know if anything more required.

Thanks in advance.


#2

@verelly

Please ZIP and attach your input Word document here for testing. We will investigate the issue on our side and provide you more information.


#3

Please find the attached zipped containing input file.
But, application will have multiple files in similar format as input files with DIFFERENT set of data.

04.05.00-B___ABC.DOCx.zip (19.3 KB)

Thanks.


#4

@verelly

Unfortunately, we have not found any Unicode’s or special characters in the document. Could you please share the content’s detail that you want to replace? We will investigate the issue and provide you more information on it.


#5

please refer the attached image “footerunicode.png” showing Unicode with red border box.

FooterUnicodes.png (13.1 KB)

“\u0014…” “\u001” etc…

Also present is the code that i am using

Document docFooterRplace = new Document(JobFolderPath + filename);
HeaderFooterCollection headersFooters = docFooterRplace.FirstSection.HeadersFooters;
HeaderFooter footer = headersFooters[Aspose.Words.HeaderFooterType.FooterPrimary];
FindReplaceOptions options = new FindReplaceOptions
{
MatchCase = false,
FindWholeWordsOnly = false
};
footer.Range.Replace(new System.Text.RegularExpressions.Regex(@"[^\u0014-\u007E]"), “”, options);
docFooterRplace.Save(JobFolderPath + “\HeaderFooter.ReplaceText.doc”);

Thanks.


#6

@verelly

We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-18584. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.


#7

Ok thanks for the update.
Waiting for you resolution.

Thanks.


#8

@verelly

You are replacing text inside fields. Range.Replace does not replace text inside field. Could you please share what you actually want to do and why you need these characters block replacement? It would be great if you please share your original document and expected output document. We will then implement this feature accordingly. Thanks for your cooperation.


#9

Hello Team,

My requirement is to replace only the FOOTER text after the document is generated.

e.g. “Rev. 3, 02 May 19” with say “Rev. 12ABC, 04 June 2019”

Please find attached “Spec footer issue.zip”. It contains 02 document files.

The text with ‘Yellow’ back-color is dynamic text coming from Database Tables.

  1. Template design .docX : - This is template saved in database. It has tables in Header & Footer designing which are invisible in Output file .

  2. Final Output Format .docX : - This is Output / Generated document.

I hope this will provide you with required information. Code is shared in previous thread.Spec footer issue.zip (36.1 KB)

Thanks.


#10

@verelly

You can simply achieve your requirement using following line of code.

footer.Range.Replace("Rev. 3, 02 May 19", "Rev. 12ABC, 04 June 2019", options);


#11

Hello,

I am aware of this functionality. But it works when the Text is Static. Means it can be hard-coded.

Please refer initial discussions where I have provided screen shot of how Unicode characters are coming when using replace function.

FooterUnicodes.png (13.1 KB)
“FooterUnicodes.png”.

In my case as shown in document it will be dynamic. Any text can come.

Thanks.


#12

@verelly

Thanks for sharing the detail. Could you please share why you need unicode characters block replacement? We will then log your issue in our issue tracking system accordingly.


#13

Hello,

Already a ticket “WORDSNET-18584” is present. I have provided sample document for this issue.

While using Replace( … ) function if the Text string has Unicode’s in it.
Due to this text is not replaced.

So before replacing the text the Unicode’s has to be removed then only Replace function will work when Text is dynamic.

Thanks.


#14

@verelly

We have logged the shared detail in our issue tracking system. We will inform you via this forum thread once this issue is resolved.