如何在PdfPCell中为最后一行包装文本生成数据表点头 [英] How to Generate Table-of-Figures Dot Leaders in a PdfPCell for the Last Line of Wrapped Text

查看:120
本文介绍了如何在PdfPCell中为最后一行包装文本生成数据表点头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用PDFPTable生成的数据表。

I have a Table of Figures generated using PDFPTable like so.

-------------------------------------- 
|Caption|Figure Title           |  PP|
-------------------------------------- 
| fig 1 |title text             |  2 |
--------------------------------|----|
| fig 2 | This is a longer title|    |
|       | text that wraps       | 55 |
--------------------------------------
| fig N | another title         | 89 |
--------------------------------------

我需要从最后一行文字生成领导点;它可能已经包裹在细胞中。

I need to generate leader dots from the last line of text; it may have wrapped in the cell.

这是一个示例再次显示图2项目的包装标题文本,另外还有从文本末尾到单元格右侧的引导点。

Here's a sample again showing the Figure 2 item of wrapped titled text and additionally having leader dots from the end of the text to the right side of the cell.

| fig 2 | This is a longer title|    |
|       | text that wraps.......| 55 |

这就是我想要实现的目标。

This is what I want to achieve.

当我写单元格文本时,我不知道它将在哪里换行,因此我不知道最后一行文本是用于测量的它,如果我知道最后一行文字,我很难找到它后面的直接x位置。

When I write the cell text I don't know where it will wrap and therefore I don't know what the last line of text will be for the purpose of measuring it, and if I do know about the last line of text I'm hard pressed to find the immediate x position following it.

到目前为止,我已尝试利用单元格事件表事件在事后写出领导点。到目前为止阻止我的两个问题是:

So far, I've tried harnessing Cell Events and Table Events to write the leader dots after the fact. The two problems that have stopped me so far are:


  1. 我在最后一行之后找不到x位置包裹文字。

  1. I can't find the x position directly after the last line of wrapped text.

如果我尝试在整个最后一行文本下面的底层点策略(所以我不必知道它在x位置停止的位置。我现在做y位置)唯一允许点出现的画布是PdfPTable.TEXTCANVAS但是它将引导点写在现有文本的顶部而不是下面。我可以给文本块一个背景颜色,所以如果它后面有一些领导点,它们将不可见(一个穷人的作物)。

If I try the strategy of underlying dots beneath the entire last line of text (so I don't have to know where it stops in the x position. I do now the y position) the only canvas that allows the dots to appear is PdfPTable.TEXTCANVAS however it writes the leader dots on top of the existing text instead of beneath. I can give the text chunk a background color, so if some leader dots exist behind it they will not be visible (a poor man's crop).

我对PDFPTable上下文中的任何策略持开放态度。

I'm open to any strategy inside the context of the PDFPTable.

推荐答案

首先要做的事情:+1为你的问题以及你自己提供的答案。

First things first: +1 for your question and the answer you provided yourself.

但是......

虽然你的答案可能有效,但有更好的方法来实现你的目标。我写了一个名为 DottedLineLeader 的小样本,作为一种更容易维护的替代方案。此示例使用包含在对象中的 DottedLineSeparator

Although your answer may work, there is a better way to achieve your goal. I've written a small sample called DottedLineLeader as an alternative that will be much easier to maintain. This example uses the DottedLineSeparator wrapped in a Chunk object.

看一下如何使用这样的块分隔符

Take a look at how such a chunk separator is used:

Chunk leader = new Chunk(new DottedLineSeparator());
Paragraph p;
p = new Paragraph("This is a longer title text that wraps");
p.add(leader);

当我们将段落添加到 PdfPCell ,我们得到以下效果:

When we add this Paragraph to a PdfPCell, we get the following effect:

虚线中的点不是'。'字符。相反,它是具有特定划线图案的实际线(矢量数据)。使用这种方法而不是您自己的方法,将显着减少代码中的行数,使用更少的CPU并生成更清晰的 PDF。

The dots in the dotted line are not '.' characters. Instead it's an actual line (vector data) with a specific dash pattern. Using this approach instead of your own, will significantly reduce the number of lines in your code, use less CPU and result in cleaner PDFs.

这篇关于如何在PdfPCell中为最后一行包装文本生成数据表点头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆