C# MigraDoc:如何将前面的空格添加到字符串中?

C# MigraDoc:如何将前面的空格添加到字符串中?,c#,string,pdf,pdfsharp,migradoc,C#,String,Pdf,Pdfsharp,Migradoc,我有一个文本数据表,我想将某些数据段缩进两个空格,但我尝试的所有操作似乎都会导致自动修剪字符串,并删除前面的空格。目前的PDF格式如下所示: 例如,我想缩进一下'LiabilityOne'和'LiabilityTwo'。我已经尝试在字符串渲染时添加空格。在渲染之前添加空格,使用“\x020”希望能保持不变,并使用PadLeft(String.Length+2,”),所有这些都没有运气 当然,有一种方法可以将前面的空格添加到这些字符串中。我怎么做 编辑: Context——这是为右边表的后半部分

我有一个文本数据表,我想将某些数据段缩进两个空格,但我尝试的所有操作似乎都会导致自动修剪字符串,并删除前面的空格。目前的PDF格式如下所示:

例如,我想缩进一下'LiabilityOne'和'LiabilityTwo'。我已经尝试在字符串渲染时添加空格。在渲染之前添加空格,使用“\x020”希望能保持不变,并使用PadLeft(String.Length+2,”),所有这些都没有运气

当然,有一种方法可以将前面的空格添加到这些字符串中。我怎么做

编辑:

Context——这是为右边表的后半部分生成内容的方法。其他一切都非常相似

private void DrawStaticLiabilities()
{
    _PdfVerticalOffset = 85 + (_PdfRowsFSRight * _PdfRowHeight);

    Document tDoc = new Document();
    MigraDoc.DocumentObjectModel.Style style = tDoc.Styles["Normal"];
    style.Font.Name = tPdfFont;
    style.Font.Size = 10;
    Section tSec = tDoc.AddSection();
    MigraDoc.DocumentObjectModel.Tables.Table table2 = new MigraDoc.DocumentObjectModel.Tables.Table();
    table2 = tSec.AddTable();
    table2.Borders.Width = 0.2;
    table2.Rows.LeftIndent = 0;

    Column columnData2 = table2.AddColumn("295pt");
    Column columnValue2 = table2.AddColumn("70pt");
    columnValue2.Borders.Right.Visible = false;

    Row rowAb = table2.AddRow();
    rowAb.Borders.Top.Visible = true;
    rowAb.Borders.Bottom.Visible = false;
    rowAb.Cells[0].AddParagraph(MP.FormFinancialStatement.StaticLiabilites.TopLine);
    rowAb.Cells[1].AddParagraph("");

    Row row1b = table2.AddRow();
    row1b.Borders.Bottom.Visible = false;
    row1b.Cells[0].AddParagraph("  Intermediate Liabilities  (" + MP.FormFinancialStatement.StaticLiabilites.IntLiabilitiesText + ")");
    row1b.Cells[1].Format.Alignment = ParagraphAlignment.Right;
    row1b.Cells[1].AddParagraph(MP.FormFinancialStatement.StaticLiabilites.IntLiabilitiesValue);

    Row row2b = table2.AddRow();
    row2b.Borders.Bottom.Visible = false;
    row2b.Cells[0].AddParagraph("  Long Term Liabilities (" + MP.FormFinancialStatement.StaticLiabilites.LongLiabilitiesText + ")");
    row2b.Cells[1].Format.Alignment = ParagraphAlignment.Right;
    row2b.Cells[1].AddParagraph(MP.FormFinancialStatement.StaticLiabilites.LongLiabilitiesValue);

    Row row3b = table2.AddRow();
    row3b.Borders.Bottom.Visible = false;
    row3b.Cells[0].AddParagraph("  Accrued Interest On: (" + MP.FormFinancialStatement.StaticLiabilites.AccruedInterestText + ")");
    row3b.Cells[1].AddParagraph("");

    Row row4b = table2.AddRow();
    row4b.Borders.Bottom.Visible = false;
    row4b.Cells[0].AddParagraph("  Accounts and Notes Payable(" + MP.FormFinancialStatement.StaticLiabilites.AccountsPayableText + ")");
    row4b.Cells[1].Format.Alignment = ParagraphAlignment.Right;
    row4b.Cells[1].AddParagraph(MP.FormFinancialStatement.StaticLiabilites.AccountsPayableValue);

    Row row5b = table2.AddRow();
    row5b.Borders.Bottom.Visible = false;
    row5b.Cells[0].AddParagraph("  Intermediate Liabilities (" + MP.FormFinancialStatement.StaticLiabilites.OtherIntLiabilitiesText + ")");
    row5b.Cells[1].Format.Alignment = ParagraphAlignment.Right;
    row5b.Cells[1].AddParagraph(MP.FormFinancialStatement.StaticLiabilites.OtherIntLiabilitiesValue);

    Row row6b = table2.AddRow();
    row6b.Borders.Bottom.Visible = false;
    row6b.Cells[0].AddParagraph("  Long Term Liabilities (" + MP.FormFinancialStatement.StaticLiabilites.OtherLongLiabilitiesText + ")");
    row6b.Cells[1].Format.Alignment = ParagraphAlignment.Right;
         row6b.Cells[1].AddParagraph(MP.FormFinancialStatement.StaticLiabilites.OtherLongLiabilitiesValue);

    MigraDoc.Rendering.DocumentRenderer docRenderer = new DocumentRenderer(tDoc);
    docRenderer.PrepareDocument();
    docRenderer.RenderObject(gfx, 405, _PdfVerticalOffset, "365pt", table2);

    _PdfRowsFSRight += 8;
}

要使用MigraDoc获得多个相邻空格,只需使用非中断空格(按Alt+)

另请参见:

需要更多的上下文。我不知道该表是如何以这种方式设计的,我用一段代码更新了OP,希望这段代码有用。