Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
579 views
in Technique[技术] by (71.8m points)

itextsharp - Image alignment in text?

Using iTextSharp i'm 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 tried

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. There was no textwrap in effect.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...