2011-05-17 46 views
1

是否有可能在iTextSharp中創建浮動圖像並使文本在其周圍流動。我在下面做了,圖像沒有插入,但只有元素。使用iTextSharp中的填充在文本週圍創建浮動圖像

 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 

有人可以糾正代碼。我需要做些什麼來讓圖像像這個鏈接一樣浮動Stackoveflow Link

回答

2

我相信一個PdfPCell是一個圖像或一個元素容器。然而,塊(在短語或段落內)本身可以是圖像。

還有還有myImage.setAlignment(Image.TEXTWRAP);

如果沒有其他什麼比廣場周圍的邊框圖像的包我會感到震驚,但它仍然遠遠不是更好。

請注意,如果包裝在PdfPTable中,這可能不起作用,因爲它們會執行大部分自己的佈局。

+0

我使用的版本沒有該方法。它有一個屬性'Alignment' – Deeptechtons 2011-05-18 05:49:45

+0

iText中的所有通用Java「get/set」方法都是iTextSharp中的屬性。在這種情況下:'myImage.Alignment = Image.TEXTWRAP;' – 2011-05-18 16:02:37

+0

我仍然沒有得到解決。僅僅因爲我沒有收到任何來自社區的答案,我會標記這一點。 – Deeptechtons 2011-05-19 04:43:50

相關問題