【发布时间】:2017-06-12 17:20:57
【问题描述】:
我正在 iTextSharp 生成的 PDF 文件中绘制一个方程。没什么复杂的,比如:
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,我没有可以调用 SetGenericTag() 的 Chunk,而且我不知道页面上等式的位置。
创建 PdfTemplate 是不是走错路了?我是否需要使用其他方法创建我的方程,以便我可以获取一个块并调用 SetGenericTag()?或者有什么方法可以找出方程式的位置,以便我可以创建我的 PushbuttonField?
===== 稍后添加
我刚刚意识到我可以稍后移动模板的绘图,我可以在 OnCloseDocument() 处理程序期间进行绘图,我假设此时它已经完成了所有布局,因此它确切知道模板的绘制位置。但是不知道怎么问模板是在哪里画的……
【问题讨论】: