2014-05-09 42 views
0

我創建了一個包含48個圖像的表格。我把它放在細胞的右側。所以我想把相同的單元格放在圖像的數量上。在左側。與itextsharp相同的單元格中的文本和圖像

這裏是我的部分代碼:

for (int i = x; i <= 48; i += 4) 
{ 
    int number = i + 4; 
    imageFilePath = "images/image" + number + ".jpeg"; 
    jpg = iTextSharp.text.Image.GetInstance(imageFilePath); 
    jpg.ScaleAbsolute(166.11023622047f, 124.724409448829f); 
    jpg.BorderColor = BaseColor.BLUE; 
    string numberofcard = i.ToString(); 
    cell = new PdfPCell(jpg); 
    cell.FixedHeight = 144.56692913386f; 
    cell.Border = 0; 
    cell.HorizontalAlignment = Element.ALIGN_RIGHT; 
    cell.VerticalAlignment = Element.ALIGN_MIDDLE; 
    table5.AddCell(cell); 
} 

我怎麼會在電池的左上角插入圖片的數量?

+0

我會使用單元格事件來做到這一點。 –

+0

我怎麼能做到這一點? – NickName

回答

1

下面是一個例子。

您需要創建自定義IPdfPCellEvent實現。

private class MyEvent : IPdfPCellEvent { 
    string number; 
    public MyEvent(string number) { 
     this.number = number; 
    } 
    public void CellLayout(PdfPCell cell, Rectangle position, PdfContentByte[] canvases) { 
     ColumnText.ShowTextAligned(
      canvases[PdfPTable.TEXTCANVAS], 
      Element.ALIGN_LEFT, 
      new Phrase(number), 
      position.Left + 2, position.Top - 16, 0); 
    } 
} 

正如你可以看到,我們添加一個Phrase與絕對位置的內容number。在這種情況下:除了單元格的左邊框外,還有2個用戶單元,在單元格的頂部以下有16個用戶單元。

在您的代碼段,你再補充:

cell.CellEvent = new my_event(n); 

nnumber字符串值。現在每次渲染單元格時都會繪製數字。

相關問題