画布类实现:

 1 public  class GrapTool
 2 {     
 3     
 4      public GrapTool()
 5       {         
 6       }
 7  
 8       private Graphics g;
 9       protected Graphics G
10       {
11           get
12           {
13               if (g==null)
14               {
15                   Bitmap bm = new Bitmap(800, 15);
16                   g= Graphics.FromImage(bm);
17               }
18               return g;
19           }
20       }
21       private Font f;
22       protected Font F
23       {
24           get
25           {
26               if (f==null)
27               {
28                   f=new Font("Arial", 8);  
29               }
30               return f;
31           }
32       }
33 
34 
35       public  float GetWidth(string src)
36        {        
37              SizeF siF= G.MeasureString(src,F);           
38              return siF.Width;            
39        }
40 }

 

itextsharp实现:

1 BaseFont bf = BaseFont.createFont(BaseFont.HELVETICA , BaseFont.CP1252 , BaseFont.NOT_EMBEDDED);
2 float pageLen = bf.getWidthPoint("abc 123 abc 123" , 12);

 

相关文章:

  • 2022-12-23
  • 2021-09-07
  • 2021-10-14
  • 2023-02-25
  • 2022-01-18
  • 2022-12-23
  • 2021-06-21
  • 2021-10-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-10
  • 2022-02-26
  • 2021-12-12
  • 2022-12-23
  • 2021-06-21
相关资源
相似解决方案