2016-06-28 18 views

回答

0

如果你說「旋轉」,你的意思是「交流」。這在iText in Action書籍的第5章中的示例AlternatingBackground中進行了解釋。這個例子的C#版本可以在這裏找到:AlternatingBackground.cs

你創建你定義了這個方法的TableEvent實現:

public void TableLayout(
    PdfPTable table, float[][] widths, float[] heights, 
    int headerRows, int rowStart, PdfContentByte[] canvases 
) { 
    int columns; 
    Rectangle rect; 
    int footer = widths.Length - table.FooterRows; 
    int header = table.HeaderRows - table.FooterRows + 1; 
    for (int row = header; row < footer; row += 2) { 
    columns = widths[row].Length - 1; 
    rect = new Rectangle(
     widths[row][0], heights[row], 
     widths[row][columns], heights[row + 1] 
    ); 
    rect.BackgroundColor = BaseColor.YELLOW; 
    rect.Border = Rectangle.NO_BORDER; 
    canvases[PdfPTable.BASECANVAS].Rectangle(rect); 
    } 
} 

您可以使用此事件是這樣的:

IPdfPTableEvent Pevent = new AlternatingBackground(); 
logotable.TableEvent = Pevent; 

嘗試首先看到效果的獨立示例。然後根據自己的需要調整AlternatingBackground類。

+0

謝謝。我只是看不到交替背景()在哪裏? – user1869407

+0

「public class AlternatingBackground implements PdfTableEvent」是上面tableevent必須嵌套的類。這是Java嗎?我希望c#等價。謝謝! – user1869407

+0

你是什麼意思?你是否說鏈接http://gitlab.itextsupport.com/itextsharp/book/raw/master/iTextExamplesWeb/iTextExamplesWeb/iTextInAction2Ed/Chapter05/AlternatingBackground.cs不起作用? (因爲它適用於我。) –