本文介绍了如何将图像和文本放在iText Android表中的1个单元格内?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将图像和文字置于其上方/上方?
How to put image and text below/above it?
我尝试了下面的代码,但我只能看到测试1和测试3
I tried below code but I only can see "Test 1" and "Test 3"
private void createTable(Paragraph paragraph, Document document){
PdfPTable table = new PdfPTable(2);
PdfPCell c1 = new PdfPCell(new Phrase("Question"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
c1 = new PdfPCell(new Phrase("Answer"));
c1.setHorizontalAlignment(Element.ALIGN_CENTER);
table.addCell(c1);
table.setHeaderRows(1);
HierarchyElement formElement;
FormController formController = Collect.getInstance().getFormController();
Image imageAnswer = null;
for(int i = 0; i < mFormList.size(); i++){
formElement = mFormList.get(i);
table.addCell(formElement.getPrimaryText());
String imageName = getImageNameOfSelectedAnswer(formController, formElement);
if(imageName != null){
imageAnswer = Image.getInstance(imageName);
imageAnswer.scalePercent((float) 0.1);
}
PdfPCell cell = new PdfPCell();
cell.addElement(new Paragraph("Test 1"));
cell.addElement(new Chunk(imageAnswer, 0, 0, true));
cell.addElement(new Paragraph("Test 3"));
table.addCell(cell);
}
paragraph.add(table);
document.add(paragraph);
}
推荐答案
你应该试试这个:
PdfPTable table = new PdfPTable(2);
PdfPCell cell = new PdfPCell();
Paragraph paragraph1 = new Paragraph();
paragraph1.add(textAnswer);
cell.addElement(paragraph1);
cell.addElement(new Paragraph("Test 1"));
cell.addElement(imageAnswer);
cell.addElement(new Paragraph("Test 3"));
table.addCell(cell);
如果这不起作用,请提供一个用Java重现问题的SSCCE。
If that doesn't work, please provide a SSCCE that reproduces the problem in Java.
这篇关于如何将图像和文本放在iText Android表中的1个单元格内?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!