c# - 如何在 MigraDoc 中的表格周围添加边框?

标签 c# migradoc

有没有办法在表格周围添加边框并隐藏 MigraDoc 中的单元格边框?

最佳答案

边框的默认宽度为 0,边框不可见。要启用边框,请设置一个大于 0 的值。

如果 table 是您的 Table 对象,您可以编写 table.Borders.Width = 0.5;

您可以为表格和每个单元格设置边框。单元格从表格、列、行继承边框属性,除非它们在较低的阶段被覆盖。

还要检查 Table 类的 SetEdge 方法。

此处讨论的示例代码:
http://www.pdfsharp.net/wiki/Invoice-sample.ashx

我的测试代码:

private static void TabelWithBorderTest()
{
    var document = new Document();

    // Add a section to the document.
    var section = document.AddSection();

    Table table = section.AddTable();
    table.Borders.Width = 0.25;
    table.Rows.LeftIndent = 0;

    // Before you can add a row, you must define the columns
    Column column = table.AddColumn("7cm");
    column.Format.Alignment = ParagraphAlignment.Left;

    Row row = table.AddRow();
    row.Cells[0].AddParagraph("Text in table");

    // Create a renderer for the MigraDoc document.
    var pdfRenderer = new PdfDocumentRenderer(false) { Document = document };

    // Associate the MigraDoc document with a renderer.

    // Layout and render document to PDF.
    pdfRenderer.RenderDocument();

    // Save the document...
    const string filename = "TableTest.pdf";
    pdfRenderer.PdfDocument.Save(filename);
    // ...and start a viewer.
    Process.Start(filename);
}

关于c# - 如何在 MigraDoc 中的表格周围添加边框?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45737856/

相关文章:

c# - c#中参数前使用 "this."是不是占用更多内存?

c# - 在c#中读取原始图像文件

c# - 如何让 Visual Studio 在调试时使用嵌入式源代码?

c# - MigraDoc 截面宽度

pdfsharp - MigraDoc - 获取页码

c# - 如何在 MigraDoc 库中设置文档方向(针对所有页面)?

c# - 基于 switch-case 结果在同一个变量上使用不同构造函数的方法

c# - 在文件流传输中实现停止和重新启动 - 如何实现? C# 网络

c# - 将 PDF 模板与 PDFSharp 和/或 MigraDoc 结合使用

c# - 在 MigraDoc 中将页码与右角对齐