tags:

views:

1019

answers:

1

Using iTextSharp im trying to align an image so that it gets embedded in a paragraph. I can do it like this:

iTextSharp.text.Image image;
image.Alignment = Image.ALIGN_RIGHT | Image.TEXTWRAP;
document.Add(image);
document.Add(new Paragraph("Large string of text goes here"));

But the image comes out on the top right with the text surrounding it (kind of like an L)

What I want is the text to be a few paragraphs then the image with text below it (kind of like a C). Does anyone know how I would do this VIA iTextSharp?

Edit:

I also tired

iTextSharp.text.Image image;
image.Alignment = Image.ALIGN_RIGHT | Image.TEXTWRAP | Image.ALIGN_MIDDLE;
document.Add(image);
document.Add(new Paragraph("Large string of text goes here"));

But it was displayed with the image at the top and the text below it. No textwrap in effect.

+1  A: 

The Phrase and the Paragraph objects do behave differently. Try changing to:

image.Alignment = 6;
document.Add(image);
document.Add(new Phrase("Large string of text goes here"));

This worked for me in VB. ( I had to change the image alignment to the sum of the integer values for ALIGN_RIGHT and TEXTWRAP to get this to work properly).

ALIGN_RIGHT = 2
TEXTWRAP = 4

Your image was displayed at the top of the page because it was the first thing added to the document, and the text was added after it. You can move the image down by either setting its absolute position, or by adding some of your text to the document, then adding the image, then adding the rest of your text.

Stewbob
Adding part of the text, then the image, then the rest of the text worked.
Zenox