2011-04-28 154 views

回答

0

最簡單的方法是通過PdfPageEvent中的onGenericTag處理程序。

您通過Chunk.setGenericTag(String tag)爲該單元格的內容指定了一個通用標記,並設置了一個PdfPageEvent處理程序,該程序將在繪製該組塊時繪製您的線條。

喜歡的東西:

public class MyPdfPageEvent extends PdfPageEventHelper { 
    public void onGenericTag(PdfWriter writer, Document doc, Rectangle rect, String tag) { 
     PdfContentByte canvas = writer.getDirectContent(); 
     canvas.saveState(); 
     canvas.setColorStroke(Color.BLACK); // or whatever 
     // You can also mess with the line's thickness, endcaps, dash style, etc. 
     // Lots of options to play with. 
     canvas.moveTo(rect.getLeft(), rect.getBottom()); 
     canvas.lineTo(rect.getRight(), rect.getTop()); 
     canvas.stroke(); 
     canvas.restoreState(); 
    } 
} 
+0

嘿謝謝,你的回答很有幫助 – richardhell 2011-05-03 00:04:45

0

嘛。 @Mark Storer的回答很有幫助,在這種情況下,我使用了「PdfPCellEvent」來禁止這種方法。

謝謝馬克!