我在iTextSharp生成的PDF文件中绘制方程。没有什么复杂的,这样的东西:iText(Sharp) - 按钮字段里面的模板里面的单元格
x-y
--- + 3
z
但有两个有趣的警告:
- 方程式得出,具有一定的文字一起,在一个表格单元格
- 表绘制的结构化文档中(章节),所以我不知道细胞将在何处被绘制。
我在模板绘制方程求解这样的:
section.Add(new Paragraph("Here comes my equation in a table"));
PdfPTable outerTable = new PdfPTable(2);
outerTable.AddCell(new PdfPCell(new Phrase(new Chunk("Look at the next cell"))));
PdfTemplate template = pdfWriter.DirectContent.CreateTemplate(bounds.Width, bounds.Height);
draw_my_equation_into(template);
Image image = iTextSharp.text.Image.GetInstance(template);
PdfPTable innerTable = new PdfPTable(1); // Inner table, inside cell (1, 0) in my outer table.
innerTable.AddCell(new PdfPCell(new Phrase(new Chunk("Here is my equation:"))));
innerTable.AddCell(new PdfPCell(image));
outerTable.AddCell(innerTable);
section.Add(outerTable);
chapter.Add(section);
这工作正常。好东西。
但是现在我意识到如果他们想要,我想给文档的读者一些帮助理解方程,所以如果将鼠标悬停在方程上并让它们跳到如果他们点击这个等式,甚至会有更多的解释我知道这样做的唯一方法是在块as seen here上使用PushbuttonField和通用标签。
但我无法弄清楚在这种情况下如何添加一个PushbuttonField,我没有一个Chunk来调用SetGenericTag(),并且我不知道方程在页面上的位置。
正在创建一个PdfTemplate错误的方式去这里?我是否需要使用其他方法创建我的公式,以便可以获得一个Chunk并调用SetGenericTag()?还是有一些方法来找出方程的位置,所以我可以创建我的按钮字段?
=====后来添加
我才意识到,我可以稍后移动模板的附图中,OnCloseDocument()处理过程中,我可以做图纸,我认为在这一点上它的完成所有的布局,因此它确切知道模板的绘制位置。但我不知道怎么问我结束了一个颇为曲折,但功能的解决方案的基础上,增加一个CellEvent到包含公式的单元格在那里它被绘制模板...