【问题标题】:MigraDoc FormattingMigraDoc 格式化
【发布时间】:2018-06-18 14:40:51
【问题描述】:

我对 PDF 创建(包括 MigraDoc)完全陌生。我已经走到了这一步,这真的很接近我现在想要的。我的问题是,我传递给“bodyParagraph”的文本字符串(myMessage)长达 100 行,这会导致创建三个页面,这很好。但是第一页的上边距略大于第二页和第三页。我不知道为什么...

基本上,我试图创建相同的每个页面。无论“bodyParagraph”内容中的行数如何,相同的页眉、页脚和正文占用相同的空间。如果我采取了完全错误的方法,我会接受建议。

另外,如果有一个好的教程可以让我指出那将是很棒的。除了样品,我真的找不到任何东西。我从示例中学到了一切,但部分、段落等对我来说都是新的,我想更好地了解我所做的事情。

public static Document CreateWorkOrderPDF2(Document document, string filename, string WorkOrderHeader, string myMessage)
    {
        Section section = document.AddSection();
        section.PageSetup.PageFormat = PageFormat.Letter;

        section.PageSetup.StartingNumber = 1;

        section.PageSetup.LeftMargin = 40;
        //Sets the height of the top margin
        section.PageSetup.TopMargin = 100;
        section.PageSetup.RightMargin = 40;
        section.PageSetup.BottomMargin = 40;

        //MARGIN
        HeaderFooter header = section.Headers.Primary;
        header.Format.Font.Size = 16;
        header.Format.Font.Color = Colors.DarkBlue;

        MigraDoc.DocumentObjectModel.Shapes.Image headerImage = header.AddImage("../../Fonts/castorgate.regular.png");
        headerImage.Width = "2cm";

        Paragraph headerParagraph = section.AddParagraph();
        headerParagraph = header.AddParagraph(WorkOrderHeader);

        //BODY PARAGRAPH
        Paragraph bodyParagraph = section.AddParagraph();
        bodyParagraph = section.AddParagraph(myMessage);
        bodyParagraph.Format.Font.Size = 10;
        bodyParagraph.Format.Font.Color = Colors.DarkRed;


        //paragraph.Format.Distancne = "3cm";
        Paragraph renderDate = section.AddParagraph();
        renderDate = section.AddParagraph("Work Order Generated: ");
        renderDate.AddDateField();

        return document;
    }

【问题讨论】:

    标签: format migradoc


    【解决方案1】:

    Paragraph bodyParagraph = section.AddParagraph(); 行添加了一个空段落。我假设这是第一页上的额外空间。
    以下代码块中的 renderDate 存在相同问题。 如果您不想要它们,只需删除调用 section.AddParagraph() 即可删除空段落。

    MigraDoc 与 Word 和理解部分、段落等非常相似。在 Word 中也将帮助您使用 MigraDoc。这些知识以及示例和 IntelliSense 应该可以帮助您继续前进。

    您可以使用 MigraDoc 创建 RTF 文件,在 Word 中打开 RTF,然后单击 pilcrow 以在 Word 中显示格式字符。

    【讨论】:

    • 就是这样。谢谢。感谢您提供有关 RTF 的提示。这应该有助于我了解发生了什么......
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-23
    • 2014-08-21
    • 2010-11-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多