Add Table

Documentize PDF Manager for .NET 是一个多功能组件,旨在简化将表格集成到 PDF 文档中的过程。无论是组织数据、设计表单,还是提升文档可读性,该组件都能在保持精确和高效的同时,使工作变得更简单。

创建带表格的 PDF

按照以下步骤使用 TableOptions 类在 PDF 中创建结构化表格:

  1. 配置 TableOptions 对象,以定义表格结构、内容以及输入/输出文件。
  2. 向 PDF 添加表格、行和单元格。
  3. 使用 AddTable 方法完成表格生成过程。

示例代码:

 1// Configure table options
 2var options = new TableOptions();
 3options.InsertPageBefore(1)
 4   .AddTable()
 5        .AddRow()
 6            .AddCell().AddParagraph("Name")
 7            .AddCell().AddParagraph("Age")
 8        .AddRow()
 9            .AddCell().AddParagraph("Bob")
10            .AddCell().AddParagraph("12")
11        .AddRow()
12            .AddCell().AddParagraph("Sam")
13            .AddCell().AddParagraph("20")
14        .AddRow()
15            .AddCell().AddParagraph("Sandy")
16            .AddCell().AddParagraph("26")
17        .AddRow()
18            .AddCell().AddParagraph("Tom")
19            .AddCell().AddParagraph("12")
20        .AddRow()
21            .AddCell().AddParagraph("Jim")
22            .AddCell().AddParagraph("27");
23// Add input file path
24options.AddInput(new FileData("path_to_input.pdf"));
25// Set output file path
26options.AddOutput(new FileData("path_to_output.pdf"));
27// Perform the process
28PdfManager.AddTable(options);

设置表格所在页

按照以下步骤在第 2 页之前创建表格:

示例代码:

 1// Configure table options
 2var options = new TableOptions();
 3options.InsertPageBefore(2) // Add table before page 2
 4   .AddTable()
 5        .AddRow()
 6            .AddCell().AddParagraph("Name")
 7            .AddCell().AddParagraph("Age");
 8// Add input file path
 9options.AddInput(new FileData("path_to_input.pdf"));
10// Set output file path
11options.AddOutput(new FileData("path_to_output.pdf"));
12// Perform the process
13PdfManager.AddTable(options);

关键特性:

  • 动态表格创建:轻松在 PDF 文档中生成结构化表格。
  • 页码定位:精准地在 PDF 的特定位置插入表格。
  • 自定义布局:可调节表格结构、单元格对齐方式和样式。
 中文