Skip to main content
 首页 » 编程设计

c#之如何使用 dbAutoTrack 使用 DrawTable

2024年02月13日12cloudgamer

我正在使用 dbAutoTrack 生成 PDF,因为我必须添加表格,但我得到了异常,比如对象引用未设置为对象的实例

下面是我的代码

  Table t=new Table(); 
  Row row=new Row(t); 
 
  row.Cells.Add("ABC"); 
  t.Rows.Add(row); 
  _pdfGraphics.DrawTable(100,200, t); 

其中 _pdfGraphics 是 PDFGraphics 的对象。 提前致谢

请您参考如下方法:

您很可能收到类似这样的消息:“此行中的列不足,列跨度为 1。”你只需要添加它们。

可行的样本:

        //Initialize a new PDF Document 
        Document _document = new Document();    
 
        _document.Title = "Аpitron Sample"; 
        _document.Author = "StanlyF"; 
        _document.Creator = "АPItron LTD."; 
 
        Page page = null; 
        PDFGraphics graphics = null; 
 
        Table _table =  new Table(); 
        _table.Columns.Add(30); 
        Row row = new Row(_table); 
        row.Height = 25; 
        row.Cells.Add("ABC"); 
        _table.Rows.Add(row); 
        while (_table != null) 
        { 
            //Initialize new page with default PageSize A4 
            page = new Page(PageSize.A4); 
 
            //Add page to document 
            _document.Pages.Add(page); 
            //Get the PDFGraphics object for drawing to the page. 
            graphics = page.Graphics; 
            _table = graphics.DrawTable(100,200, _table);  
 
        } 
 
        using(FileStream _fs = new FileStream("Table_Sample.pdf", System.IO.FileMode.Create, System.IO.FileAccess.Write))   
        { 
            //Generate PDF to the stream 
            _document.Generate(_fs); 
            Process.Start("Table_Sample.pdf"); 
        }