2009-09-20 82 views
11

使用iTextSharp我想對齊圖像,以便它嵌入到段落中。我能做到這一點是這樣的:文字中的圖像對齊?

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

但圖像出來與文本右上方周圍(有點像一個L)

我想要的是幾段文字然後是帶有文字的圖像(有點像C)。有誰知道我會如何做VIA iTextSharp?

編輯:

我也試過

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")); 

,但它是在頂部的形象和它下面的文本顯示。沒有實際的textwrap。

回答

14

短語和段落對象的行爲有所不同。嘗試改爲:

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

這在VB中適用於我。 (我必須將圖像對齊更改爲ALIGN_RIGHT和TEXTWRAP的整數值的總和以使其正常工作)。

ALIGN_RIGHT = 2 
TEXTWRAP = 4 

您的圖片在頁面的頂部顯示,因爲它是添加到文檔的第一件事,和之後加入的文字。 您可以通過設置其絕對位置,或者將一些文本添加到文檔中,然後添加圖像,然後添加其餘文本來移動圖像。

+0

添加部分文本,然後是圖像,然後是文本的其餘部分。 – Kyle 2009-10-09 22:45:50