public static PdfPCell createValueCell(String val, AdditionalInfo addInfo) throws Exception {
PdfPCell valueCell = new PdfPCell();
setBorders(valueCell, 0, 0, 1, 0);
valueCell.setBorderColorBottom(new BaseColor(242, 242, 242));
valueCell.setHorizontalAlignment(Element.ALIGN_RIGHT);
Font cellFont = FontFactory.getFont(FontFactory.HELVETICA, 10);
switch (addInfo.getOptionType()) {
case (OPTION_TYPE_MEDIA):
Image img = null;
try {
img = Image.getInstance(Base64.decode(val));
} catch (Exception e) {
throw new Exception("Problem in decoding image");
}
String mediaName = addInfo.getMediaName();
String imgName = String.format("File: %s", mediaName);
Font captionFont = FontFactory.getFont(FontFactory.HELVETICA, 6);
Paragraph caption = new Paragraph(imgName, captionFont);
valueCell.addElement(img);
valueCell.addElement(caption);
break;
default:
valueCell.setPhrase(new Phrase(val, cellFont));
}
return valueCell;
}
I'm using this code to insert in a cell some data, when the data is an image I use a switch to insert it.
Now I'm having some problems with a standard base64 image, its a Rectangle: 4160.0x3120.0 (rot: 0 degrees)
but in the PDF build by my application this image is basically rotated by 90° and I'm pretty sure that I don't apply any kind of rotation to it.
I attach the Table creation:
public static PdfPTable createTableStructure(String groupTag) {
PdfPTable table = new PdfPTable(4);
table.setWidthPercentage(100);
table.getDefaultCell().setBorder(0);
PdfPCell headerCell = new PdfPCell();
headerCell.setBackgroundColor(new BaseColor(216, 216, 216)); //dark gray
headerCell.setBorder(Rectangle.NO_BORDER);
Font headerFont = FontFactory.getFont(FontFactory.HELVETICA, 14);
headerCell.setPhrase(new Phrase(groupTag, headerFont));
headerCell.setColspan(4);
table.addCell(headerCell);
table.setSpacingAfter(20);
table.setHeaderRows(1);
table.completeRow();
return table;
}
When a cell is ready I basically make this call:
table.addCell(valueCell);