我需要一个有多个列的表格,其中我在不同单元格中具有不同的彩色圆圈,而圆圈中间有一个数字。 类似于下面的模型,但是一切都集中和平等。itextsharp在表格单元格中的圆形图像上添加文字
我曾尝试以下:
PdfContentByte canvas = writer.DirectContent;
PdfTemplate template = canvas.CreateTemplate(40, 40);
template.SetLineWidth(1f);
template.Circle(15f, 15f, 15);
template.Stroke();
iTextSharp.text.Image img = iTextSharp.text.Image.GetInstance(template);
img.Alignment = iTextSharp.text.Image.UNDERLYING | iTextSharp.text.Image.ALIGN_CENTER;
Phrase imgPhrase = new Paragraph(new Chunk(img, 1f, 1f));
PdfPCell meAnswerCell = new PdfPCell();
meAnswerCell.Colspan = 1;
meAnswerCell.BorderWidthBottom = 0;
meAnswerCell.HorizontalAlignment = Element.ALIGN_CENTER;
string meAnswerText = "1;
Phrase phrase = new Phrase(meAnswerText, questionFont);
Paragraph para = new Paragraph();
para.Add(imgPhrase);
para.Add(phrase);
para.Alignment = Element.ALIGN_CENTER;
meAnswerCell.AddElement(para);
answersTable.AddCell(meAnswerCell);
但我结束了这样的事情。 (我还没有尝试设置颜色)。我无法让图像和文字坐在同一个地方。
我自己也尝试下面这个帖子:
iTextSharp - Text overlapping image
这也解释了如何把一个事件在小区设置单元格的背景图像,但我的圈子里出现一半在页面下方。
有没有人去这个工作的例子?
谢谢,这真是太棒了!我现在在我的圈子里有我的号码,但是我怎样才能将整个事情整合到我的PPCPCell的中心? – Bex 2015-01-21 13:59:40
在文本模式下工作时:将单元格的对齐方式更改为Element.ALIGN_CENTER;在复合模式下工作时:将“Paragraph”的对齐方式改为“Element.ALIGN_CENTER”。如果对文本或复合模式有疑问,请查阅[免费电子书](https://leanpub.com/itext_so) – 2015-01-21 15:57:20