2011-04-28 152 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”来禁止这种方法。

谢谢马克!