0
 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);
Pickeroll
  • 908
  • 2
  • 10
  • 25

1 Answers1

0

Maybe the image is rotated on the original file. try to check the Orientation. maybe you need to Rotate the image

[question]Get Image Orientation and rotate as per orientation

byte[] bytes = Convert.FromBase64String(val);

    Image img;
    using (MemoryStream ms = new MemoryStream(bytes))
    {
        img= Image.FromStream(ms);
    }
if (img.PropertyIdList.Contains(274))
            {
                PropertyItem propOrientation = img.GetPropertyItem(274);
                short orientation = BitConverter.ToInt16(propOrientation.Value, 0);
                _logger.Info($" orientation {orientation}");

                if (orientation == 6)
                {
                    img.RotateFlip(RotateFlipType.Rotate90FlipNone);
                    bytesro = ImageToByteArray(img);
                    _logger.Info("after  RotateFlipType.Rotate90FlipNone");
                }
                else if (orientation == 8)
                {
                    img.RotateFlip(RotateFlipType.Rotate270FlipNone);
                    bytesro = ImageToByteArray(img);
                    _logger.Info("after  RotateFlipType.Rotate270FlipNone");
                }
                else
                {
                    // Do nothing
                    bytesro = ImageToByteArray(img);
                    _logger.Info("after  Do nothing");
                }
            }
mkl
  • 90,588
  • 15
  • 125
  • 265
rotem
  • 39
  • 5