1

Is it possible to create a Floated Image with text flowing around it in iTextSharp. I did the below and the image is not inserted but only the elements.

        Document doc = new Document();
        PdfWriter.GetInstance(doc, new FileStream(Path, FileMode.Create));
        doc.Open();//open the document
        PdfPTable table = new PdfPTable(6);
        table.WidthPercentage = 80;
        table.HorizontalAlignment = Element.ALIGN_CENTER;//80% centered

        Image imgLogo = Image.GetInstance(Server.MapPath("~/Images/image.png"));
        imgLogo.Alignment = Element.ALIGN_LEFT;
        imgLogo.Alt = "Company has sent you a Invoice";
        PdfPCell cell = new PdfPCell(providerLogo);//added image to cell

        cell.PaddingLeft = 10;//left padding 10px
        cell.AddElement(new Phrase("Company Name"));
        cell.AddElement(new Paragraph("California"));
        cell.Colspan = 3;
        cell.HorizontalAlignment = Element.ALIGN_LEFT;
        table.AddCell(cell);//Added cell with image and text but no Image at all

        cell = new PdfPCell(new Phrase("INVOICE"));
        cell.Colspan = 3;
        table.AddCell(cell);
        doc.Add(table);
        doc.Close();//close the document

Could someone correct the code. What do i need to do to make image float around like in this link Stackoveflow Link

Community
  • 1
  • 1
Deeptechtons
  • 10,945
  • 27
  • 96
  • 178

1 Answers1

2

I believe a PdfPCell is either an Image or an element container. HOWEVER, a chunk (within a phrase or paragraph) can itself be an image.

And there's also myImage.setAlignment( Image.TEXTWRAP );

I'd be shocked if that did anything other than wrap around the square borders of the image, but it's still far better than.

Note that this may not work when wrapped in a PdfPTable, as they do most of their own layout.

Mark Storer
  • 15,672
  • 3
  • 42
  • 80