iText7 - 在 PDF 文件上添加 AreaBreak

问题描述

我正在使用此数据库表中的 Pdfs 创建 itext7

+-----------------------+--------+-----+
| contents              | sUnity | sID |
+-----------------------+--------+-----+
| Set n.1               | Q400   |  83 |
| - Par 1.1             | Q400   |  84 |
| <b>bold text</b>      | Q400   |  85 |
| - Par 1.2             | Q400   |  86 |
| normal text           | Q400   |  87 |
| Set n.2               | Q400   |  88 |
| - Par 2.1             | Q400   |  89 |
| <i>italic text</i>    | Q400   |  90 |
| - Par 2.2             | Q400   |  91 |
| <u>underline text</u> | Q400   |  92 |
| - Par 2.3             | Q400   |  93 |
+-----------------------+--------+-----+

当行包含 Pdf 值时,我无法在 Set 上更改页面

Set 行之后,段落数未知...

我需要在 Pdf 这个回报

PDF 第 1 页

+-----------------------+
| Set n.1               |
| - Par 1.1             |
| <b>bold text</b>      |
| - Par 1.2             |
+-----------------------+

PDF 第 2 页

+-----------------------+
| Set n.2               |
| - Par 2.1             |
| <i>italic text</i>    |
| - Par 2.2             |
| <u>underline text</u> |
| - Par 2.3             |
+-----------------------+

我尝试使用添加我的代码没有成功

document.Add(new AreaBreak(AreaBreakType.NEXT_PAGE));

我的代码如下

if (dt.Rows.Count > 0)
{
    for (int i = 0; i < dt.Rows.Count; i++)
    {
        contents = new Paragraph(dt.Rows[i]["contents"].ToString())
            .SetTextAlignment(TextAlignment.JUSTIFIED)
            .SetFontSize(12);

        List<IElement> lst = HtmlConverter.ConverttoElements(dt.Rows[i]["contents"].ToString()).ToList();

        for (int j = 0; j < lst.Count; j++)
        {
            IBlockElement element = (IBlockElement)lst[j];

            if (dt.Rows[i]["contents"].ToString().StartsWith("Set"))
            {
                contents.SetFontSize(12)
                    .SetBold()
                    .SetFontColor(ColorConstants.BLUE);
            }
            else if (dt.Rows[i]["contents"].ToString().StartsWith("- "))
            {
                contents.SetFontSize(11)
                    .SetBold()
                    .SetFontColor(ColorConstants.BLACK);
            }
            else
            {
                contents.SetTextAlignment(TextAlignment.JUSTIFIED_ALL)
                    .SetFontSize(10)
                    .SetFontColor(ColorConstants.BLACK);
                
            }
            document.Add(element);
        }   
    }
    document.Add(new AreaBreak(AreaBreakType.NEXT_PAGE));
    dest = filename.ToString();                     
}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)