Aspose text replacement in PDF doesn't rearrange content

寵の児 提交于 2019-12-24 06:49:38

问题


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.

来源:https://stackoverflow.com/questions/45162218/aspose-text-replacement-in-pdf-doesnt-rearrange-content

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!