0
基本上,對於每個奇數行,顯示X顏色。對於每一個偶數行,顯示Y顏色。如何使用itextsharp旋轉兩個背景顏色之間的行
是似乎然而所有需要的邏輯,我不能找到一個很好的解決方案與iTextSharp的做到這一點
我的表名是PdfPTable logotable
基本上,對於每個奇數行,顯示X顏色。對於每一個偶數行,顯示Y顏色。如何使用itextsharp旋轉兩個背景顏色之間的行
是似乎然而所有需要的邏輯,我不能找到一個很好的解決方案與iTextSharp的做到這一點
我的表名是PdfPTable logotable
如果你說「旋轉」,你的意思是「交流」。這在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
類。
謝謝。我只是看不到交替背景()在哪裏? – user1869407
「public class AlternatingBackground implements PdfTableEvent」是上面tableevent必須嵌套的類。這是Java嗎?我希望c#等價。謝謝! – user1869407
你是什麼意思?你是否說鏈接http://gitlab.itextsupport.com/itextsharp/book/raw/master/iTextExamplesWeb/iTextExamplesWeb/iTextInAction2Ed/Chapter05/AlternatingBackground.cs不起作用? (因爲它適用於我。) –