iText7 html to pdf不能打断长词。

问题描述 投票:0回答:1

我正在使用iText7将html转换成pdf。 我有问题与打破长的单词。(只有在不合适的情况下才会打断单词)。

<td>The labrado is jumping over the fence tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt</td>

enter image description here

我试着覆盖IsSplitCharacter总是返回true,但这导致它在不需要的地方打破单词,如下面的图像(打破单词 "跳跃")。

public class CustomSplitCharacters : DefaultSplitCharacters
{
    public override bool IsSplitCharacter(GlyphLine text, int glyphPos)
    {
        return true;
    }
}

enter image description here

如果这个问题和其他帖子类似,我很抱歉。 但我似乎找不到正确的解决方案。 而且我没有足够的声誉来跟进这些帖子的评论。

提前感谢您的帮助。

word-wrap itext7 html2pdf
1个回答
0
投票

我已经创建了一个临时的解决方案

public class CustomSplitCharacters : DefaultSplitCharacters
{
    public override bool IsSplitCharacter(GlyphLine text, int glyphPos)
    {
        bool baseResult = base.IsSplitCharacter(text, glyphPos);
        bool myResult = IsSpecialCharacter((char)text.Get(glyphPos).GetUnicode());

        return baseResult || myResult;
    }

    private bool IsSpecialCharacter(char c)
    {
        Regex regexItem = new Regex("[a-zA-Z0-9]");

        return !regexItem.IsMatch(c.ToString());
    }
}

这对大多数情况下是可行的。 但还是不能破除一个长字。 我还是希望能得到一个极端情况的答案。 非常感谢您的回复。

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.