Image alignment in text?

佐手、 提交于 2019-12-18 07:35:28

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/1451045/image-alignment-in-text

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!