Quantcast
Channel: 吟遊詩人の戯言
Viewing all articles
Browse latest Browse all 17797

【iTextSharp】セルの中の任意位置に,直線を引きたい場合

$
0
0

セルの任意位置に直線を引きたい!とか,2重線を引きたい!!とか
丸描きたい!!!とか,いろいろ,Bitmap系の小細工をやりたい場合

たとえば,こんな感じで,下線を引きたいとか?(Borderプロパティあたりでもこれぐらいなら実現できますけど:汗)

WS000001

IPdfPCellEventインターフェースの継承クラスを作って,
CellLayout()メソッドを定義してやればよろしい感じ

ソースはこんな感じにて (セル内に丸を描きたい場合のソースはこちら)

  1. //Cell描画イベントクラス
  2. private class _add_event_MidasiLineYoko : IPdfPCellEvent {
  3.  
  4.     public void CellLayout(  PdfPCell cell, Rectangle position, PdfContentByte[] canvases)
  5.     {
  6.         PdfContentByte cb = canvases[PdfPTable.TEXTCANVAS];
  7.  
  8.         cb.SetLineWidth(1.5f);
  9.         cb.MoveTo(position.Left, position.Bottom - 3);
  10.         cb.LineTo(position.Right, position.Bottom - 3);
  11.         cb.Stroke();
  12.  
  13.         //直線だけじゃなく,丸でも,☆でも,Bitmapでも描画できまする(Bitmapだけは試してない:汗)
  14.  
  15.     }
  16.    
  17.  
  18. }
  19.  
  20.  
  21. _add_event_MidasiLineYoko line = new _add_event_MidasiLineYoko();           //Cell描画イベントクラスのインスタンスを作る
  22.  
  23.  
  24. PdfPCell cell = new PdfPCell(new Phrase("請  求  書", fntNormal));
  25. cell.HorizontalAlignment =  Element.ALIGN_LEFT ;
  26. cell.BackgroundColor = BaseColor.WHITE;
  27. cell.VerticalAlignment  = Element.ALIGN_MIDDLE;
  28. cell.FixedHeight = 22f;                                    
  29. cell.Border = Rectangle.NO_BORDER;
  30. cell.CellEvent = line;                                      // <--Cell描画イベントにインスタンスをセット
  31.  
  32. tbl.AddCell(pcell);

Viewing all articles
Browse latest Browse all 17797

Trending Articles