Aspose text replacement in PDF doesn't rearran

2019-07-31 09:57发布

问题:

I'm using Aspose to replace a set of words in an existing PDF file via a WPF application.

I took a look at this https://docs.aspose.com/display/pdfnet/Replace+Text+in+a+PDF+Document But the section 'Text Replacement should automatically re-arrange Page Contents' didn't help solve my problem which is exactly what is described in the section.

"However recently some customers encountered issues during text replace when particular TextFragment is replaced with smaller contents and some extra spaces are displayed in resultant PDF or in case the TextFragment is replaced with some longer string, then words overlap existing page contents."

The problem is if I replace a word by a shorter or longer word, there's either a blank gap or overlap.

I tried some options such as

textFragmentAbsorber.TextReplaceOptions.ReplaceAdjustmentAction = 
TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation;

or AdjustSpaceWidth but is has no effect at all.

My code is the same as the one I linked above except I only replace the text and let the rest untouched. Also my TextFragmentAbsorber looks like this

var textFragmentAbsorber = new TextFragmentAbsorber("(?i)("+ text.OriginalText +")", new TextSearchOptions(true));

With text.OriginalText being the text I want to replace with case insensitive regex.

标签: c# pdf Aspose