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

Free Support Forum - aspose.com

Aspose.Pdf 替换后的文字为什么不能换行? TextFragment .Text \n\r No effect

static void a5()
{
string dataDir4 = @“D:\4.pdf”;
string dataDir5 = @“D:\5.pdf”;
File.Delete(dataDir5);

        Font font = FontRepository.FindFont("SimSun");
        Document doc = new Document(dataDir4);
        int PageIndex = 1;
        var page = doc.Pages[PageIndex];
        TextFragmentAbsorber textFragmentAbsorber = new TextFragmentAbsorber("Short communication");
        page.Accept(textFragmentAbsorber);
        TextFragmentCollection textFragmentCollection = textFragmentAbsorber.TextFragments;
        TextFragment text = new TextFragment("bbb[\r\n]bbbbbbbbbb[\n\r]bbbbb");
        page.Paragraphs.Add(text);//这个可以
        foreach (TextFragment tf in textFragmentCollection)
        {
            tf.Text = "bbb[\r\n]bbbbbbbbbb[\n\r]bbbbb";//这就不行
        }
        doc.Save(dataDir5);

    }

@limingming

您能否尝试按如下方式指定 TextReplaceOptions,如果您仍然遇到任何问题,请与我们分享您的示例 PDF 文档,以便我们可以在我们的环境中测试场景并相应地解决它。

textFragmentAbsorber.TextReplaceOptions = new TextReplaceOptions(TextReplaceOptions.ReplaceAdjustment.WholeWordsHyphenation);