如何使用c#从动态创建的html页面获取行数

时间:2014-08-26 10:25:56

标签: c# html aspose

我有一些用于生成报告的html模板。

首先我通过按某种顺序合并这些模板来生成一个html页面,然后我将一个Final Html页面作为一个字符串作为我的输出,这是使用c#完成的。

稍后我会将此html字符串转换为PDF,将其转换为aspose文档,然后转换为pdf。这部分是用c#.net和aspose完成的。

我需要的是,每个页面包含大约20行。我需要像这样设置。每个页面应该只包含20行(这些行每个行都有内部表和行)。但我想根据主行计算,在页面中它应该只有20个。

所以从html页面或字符串格式化的html页面,有没有办法在每20个主要行之后设置一个分页符。 我只使用aspose.word而不是aspose.pdf。

在每20个主表行之后,我想添加分页符。 我已经将这个html页面生成为一个字符串,所以有没有办法检查主表行的数量并在该字符串中添加分页符。

1 个答案:

答案 0 :(得分:0)

嗯,你的查询不是很清楚。您是否需要在HTML字符串中包含分页符。这可能在您的方案中非常复杂,因为您需要检查行标记,并且在特定计数之后,您将需要包含中断。当你使用子表时,这将变得更加困难。

如果您正在使用Aspose.Words for .NET并希望split the tables到word文档中的新页面,则可以检查以下代码:

//Open document and create DocumentBuilder
Document doc = new Document(@"d:\\data\\Tables.docx");

DocumentBuilder buildr = new DocumentBuilder(doc);

//Get table from document
Table tab = doc.FirstSection.Body.Tables[0];

//We should split our table and insert breaks between parts of table.
int count = 0;
Table clone = (Table)tab.Clone(false);

int total = tab.Rows.Count % 20;

while (tab.Rows.Count  > 1)
{
    if (tab.Rows.Count > total)
    {
        clone.AppendChild(tab.FirstRow);
    }
    else
    {
        break;
    }
    if (count == 19 )
    {
        //Insert empty paragraph after original table
        Paragraph par = new Paragraph(doc);
        tab.ParentNode.InsertBefore(par, tab);

        //Insert newly created table after paragraph
        par.ParentNode.InsertBefore(clone, par);

        //Move document builder cursor to the paragraph
        buildr.MoveTo(par);

        //And insert PageBreak also you can use SectionBreakNewPage
        buildr.InsertBreak(BreakType.PageBreak);
        count = 0;
        clone = (Table)tab.Clone(false);

    }
    else
    {
        count = count + 1;
    }
}

//Save output document
doc.Save(@"d:\\data\\out.docx");

P.S。我是Aspose的社交媒体开发人员。

相关问题