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

标签 c# string pdf pdfsharp migradoc

我有一个文本数据表,我想将某些数据缩进几个空格,但是我尝试的所有操作似乎都会导致我的字符串被自动修剪,并且前面的空格被删除。现在的 PDF 看起来像这样:

http://i.imgur.com/KBK6jWS.png

例如,我想将“LiabilityOne”和“LiabilityTwo”缩进一点。我试过在呈现字符串时在字符串中添加空格。在渲染之前添加空格,使用 '\x020' 希望能坚持下去,并使用 PadLeft(String.Length + 2, ' '),一切都没有运气。

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

编辑:

上下文——这是为右侧表格的后半部分生成内容的方法。其他一切都非常相似。

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+<255>)。

也可以看看:
http://forum.pdfsharp.net/viewtopic.php?p=1304#p1304

关于c# - MigraDoc:如何将前面的空格添加到字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19300219/

相关文章:

c# - 限制文本框中的数字和字母 - C#

c - 对数组中的 2 个字符串进行排序并将它们合并为 C 中的一个

ruby - 转义 TextMate 的 $DIALOG 命令的 Ruby 字符串

c# - 使用 PDFSharp-gdi C# 将 Tiff 转换为 pdf

c# - 有没有办法用 C# 编辑 pdf?

c# - 如何在注销时清除sqlite数据库

c# - 如果我访问该对象属性,类属性是否会自动初始化?

c# - 给定一个 C# 类型,获取它的基类和实现的接口(interface)

ios - swift - 使用 replaceRange() 来更改字符串中的特定事件

python - 如何在PDF文件末尾添加空白页?