flowdocument - 在末尾插入富文本,在插入点上方创建额外的段落分隔符

发布于 2024-10-15 10:19:25 字数 958 浏览 5 评论 0原文

我正在创建一个由多个记录组成的流程文档。每条记录的顶部都包含两个表,然后是我从数据库中提取的一些富文本。附加富文本的代码位于下面(cp.Comments 包含 rtf 标记文本)。

Dim tr As TextRange
Dim arr() As Byte

Using ms As New System.IO.MemoryStream
  arr = (New System.Text.UTF8Encoding).GetBytes(cp.Comments)
  ms.Write(arr, 0, arr.Length)
  ms.Seek(0, IO.SeekOrigin.Begin)

  tr = New TextRange(fd.ContentEnd, fd.ContentEnd)   'add to end
  tr.Load(ms, DataFormats.Rtf)
End Using

流文档正确呈现第一个记录,但所有后续记录都在第一个表和第二个表之间有一个中断的情况下呈现。最奇怪的是,我在导入 RTF 之前渲染了 2 个表格,但 RTF 无论如何都会影响表格之间的间距。

fd = new FlowDocument

for each cp in SomeCollection

   fdtemp = New FlowDocument

   CreateFirstTable(cp, fdtemp)
   CreateSecondTable(cp, fdtemp)
   AddRTF(cp, fdtemp)

   FlowDocumentUtils.AddDocument(fdtemp, fd)

next

问题与集合的第一个元素中的数据无关 - 如果我告诉渲染跳过第一条记录的渲染,那么第二条记录渲染正常,但其余记录包含额外的间距。

注意:问题肯定与富文本插入有关 - 如果我注释掉 AddRTF 调用,那么所有表格都会正确呈现并粉碎在一起。 (表格边距都设置为(0,0,0,0))

有人见过这个吗?

I am creating a flowdocument that consists of multiple records. Each record contains two tables at the top, and then some rich text that I'm pulling out of a database. The code that appends the rich text is found below (cp.Comments contains the rtf tagged text).

Dim tr As TextRange
Dim arr() As Byte

Using ms As New System.IO.MemoryStream
  arr = (New System.Text.UTF8Encoding).GetBytes(cp.Comments)
  ms.Write(arr, 0, arr.Length)
  ms.Seek(0, IO.SeekOrigin.Begin)

  tr = New TextRange(fd.ContentEnd, fd.ContentEnd)   'add to end
  tr.Load(ms, DataFormats.Rtf)
End Using

The flowdocument renders the first of the records correctly, but all subsequent records are rendered with a break between the first and the second table. What is the most odd is that I'm rendering the 2 tables before importing the RTF, but the RTF is somehow affecting the spacing between the tables anyway.

fd = new FlowDocument

for each cp in SomeCollection

   fdtemp = New FlowDocument

   CreateFirstTable(cp, fdtemp)
   CreateSecondTable(cp, fdtemp)
   AddRTF(cp, fdtemp)

   FlowDocumentUtils.AddDocument(fdtemp, fd)

next

The problem isn't something related to the data in the first element of the collection - if I tell the rendering to skip the rendering of the first record, then the second record renders ok, but the rest contain the extra spacing.

Note: the problem is definitely related to the rich text insertion - if I comment out the AddRTF call, then all the tables are correctly rendered smashed together. (table margins are all set to (0,0,0,0))

Has anyone ever seen this?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

姜生凉生 2024-10-22 10:19:25

您是否检查过其他问题的解决方案:

另外,您似乎有两种单独的方法:

CreateFirstTable(cp, fdtemp)
CreateSecondTable(cp, fdtemp)

我怀疑这两种方法的操作方式之间的差异是问题所在,但不知道他们到底在做什么,我只能推测。

Have you checked out the solutions from this other question:

Also, it appears that you have two separate methods:

CreateFirstTable(cp, fdtemp)
CreateSecondTable(cp, fdtemp)

I suspect that the difference between how these two methods are operating is where the problem is, but w/out knowing what they're really doing, I can only speculate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文