We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Please suggest how to avoid table break in builder.InsertHtml

I am using
builder.InsertHtml(bodyHtmlString);
bodyHtmlString contain multiple table I dont want to break table in different page.If table is not fit in current page then whole table will go to next page

I see your posted url

http://www.aspose.com/docs/display/wordsreportingservices/Page+Breaks?showComments=true&showCommentArea=true#

http://www.aspose.com/docs/display/wordsreportingservices/Configuration+Explained

I make a file RSReportDesigner.config in said path and using
<Extension Name="AWDOC" Type="Aspose.Words.ReportingServices.DocRenderer,Aspose.Words.ReportingServices">

    DontBreakTables

still page table is break in two pages.Please suggest how to avoid table break in such situation.
I have also tried page-break-inside:avoid; within html div or table but after covert in word div or table is still breaked into different page

I am using
bodyHtmlString contain multiple table
builder.InsertHtml(bodyHtmlString);

I see your posted url

http://www.aspose.com/docs/display/wordsreportingservices/Page+Breaks?showComments=true&showCommentArea=true#

http://www.aspose.com/docs/display/wordsreportingservices/Configuration+Explained

I make a file RSReportDesigner.config in said path and using
<Extension Name="AWDOC" Type="Aspose.Words.ReportingServices.DocRenderer,Aspose.Words.ReportingServices">

    DontBreakTables


still I found table is break in two page. Please suggest how to avoid table break in different page.


Hi Goutam,


Thanks for your inquiry. Could you please share which Aspose component you are using?

If you are using Aspose.Words for .NET, please read following documentation link for your kind reference.
Keeping Tables and Rows from Breaking across Pages

If you are using Aspose.Words for Reporting Services, please use the select statement (to populate the data) inside your RDL file and share that RDL file with us. We will investigate the issue on our side and provide you more information.

Please check the following DataSet example with select statement for your kind reference.

<DataSets>

<DataSet Name=DataSet>

<Query>

<DataSourceName>DataSource</DataSourceName>

<CommandText>select 1 as value, ‘label1’ as label

union all

select 2 as value, ‘label2’ as label

union all

select 3 as value, ‘label3’ as label

union all

select 4 as value, ‘label4’ as label

</CommandText>

</Query>

<Fields>

<Field Name=value>

<DataField>value</DataField>

<rd:TypeName>System.Int32</rd:TypeName>

</Field>

<Field Name=label>

<DataField>label</DataField>

<rd:TypeName>System.String</rd:TypeName>

</Field>

</Fields>

</DataSet>

</DataSets>

Hi Tahir,


I am using Aspose.word for .Net and I write simple Html string
string strbody=
"


something
something
something

"

for generation of doc I write code

DocumentBuilder builder = new DocumentBuilder();
builder.InsertHtml(strbody);

[Note1: similar way I append header and footer in every page.]
[Note 2: though I use page-break-inside:avoid; still table is break into different page it will be better for my case if any style in html which will automatically handle it]

it can be n number of table(table width may differ) in html I want to generate a doc of pages m.
no matter how many page in doc it may be thousand and no matter how many table(it may be 2 or 3 or 4 but not 1) in a doc page but I don’t want to break any table in two pages if table is not fit in the page then it will automatically goes to next page

Hi Goutam,


Thanks for your inquiry.
Goutam:
[Note1: similar way I append header and footer in every page.]
Please read following documentation link to create header/footer.
How to Create Headers Footers using DocumentBuilder
Goutam:
[Note 2: though I use page-break-inside:avoid; still table is break into different page it will be better for my case if any style in html which will automatically handle it]
Please read following documentation link about keeping table from breaking across pages.
Keeping Tables and Rows from Breaking across Pages

It would be great if you please share following detail for our reference.

  • Please attach your input Word document.
  • Please attach your input Html
  • Please
    attach your target Word document showing the desired behavior. You can
    use Microsoft Word to create your target Word document. We will
    investigate as to how you are expecting your final document be generated
    like.

Hi Tahir,


3 input file
1)Input_Header
2)Input_Body
3)Input_Footer

Input_Header and Input_Footer are static but in Input_Body text
the number of table can be increase or decrease dynamically
headerHtml = content of Input_Header
bodyHtmlString = content of Input_Body
footerHtmlString= content of Input_Footer
The output should be in document file as Output.doc which I already generated except table not break properly .
using code like
public MemoryStream ConvertHtmlToDoc(string headerHtml, string bodyHtmlString, string footerHtmlString)
{
MemoryStream wordStream;
License license = new License();
string reportFile = string.Concat(“Aspose.Total.lic”);
license.SetLicense(reportFile);
DocumentBuilder builder = new DocumentBuilder();
PageSetup ps = builder.PageSetup;
ps.PageWidth = 800;
ps.RestartPageNumbering = true;

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.InsertHtml(headerHtml);
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
builder.InsertHtml(footerHtmlString);
// Add fields for current page number
builder.InsertField(“PAGE”, “”);
// Add any custom text
builder.Write(" / ");
// Add field for total page numbers in document
builder.InsertField(“NUMPAGES”, “”);

// Move back to the main story of the first section.
builder.MoveToDocumentStart();
builder.InsertHtml(bodyHtmlString);
wordStream = new MemoryStream();
builder.Document.Save(wordStream, SaveFormat.Doc);
return wordStream;
}

Please suggest not break table in two pages. and page number will align in same row in “Office Lease Transactions” word as in footer in output doc .

[Note: I am attaching Output.pdf which is generated properly using three input html text. I want to generate output.doc should be like Output.pdf]
Thanks in advance.you can also run three input text file as in html view.

Regards,
Goutam
Cognizant Technology Solutions
Hi Goutam,

Thanks for your inquiry.
Goutam:
The output should be in document file as Output.doc which I already generated except table not break properly .
Please note that Aspose.Words mimics the same behavior as MS Word does. If you load your html in MS Word, you will get the same output. Your input html contains one outer table with nested tables. We suggest you please remove the outer table from your html and use following code snippet to set a table to stay together on the same page.

// To keep a table from breaking across a page we need to enable KeepWithNext

// for every paragraph in the table except for the last paragraphs in the last

// row of the table.

foreach (Table table in doc.GetChildNodes(NodeType.Table, true))

foreach (Cell cell in table.GetChildNodes(NodeType.Cell, true))

{

//call this method if table's cell is created on the fly

//newly created cell does not have paragraph inside

cell.EnsureMinimum();

foreach (Paragraph para in cell.Paragraphs)

if (!(cell.ParentRow.IsLastRow && para.IsEndOfCell))

para.ParagraphFormat.KeepWithNext = true;

}

Goutam:
Please suggest not break table in two pages. and page number will align in same row in "Office Lease

Transactions" word as in footer in output doc .
The text "Office Lease Transactions" is inside a table's cell. Please add one more cell in same row and insert page fields in new cell. Hope this helps you.

Hi Tahir,


Thanks for your reply.
Still I am facing problem with table break .I change my Input Html body(pls check in attachment) as well as my code below:
public static MemoryStream ConvertToDoc(string headerHtml, string bodyHtmlString, string footerHtmlString)
{
MemoryStream wordStream;
License license = new License();
//string reportFile = string.Concat( “Aspose.Total.lic”);
string reportFile = ConfigurationManager.AppSettings[“WordLicencePath”];
license.SetLicense(reportFile);
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
PageSetup ps = builder.PageSetup;
ps.PageWidth = 800;
ps.RestartPageNumbering = true;

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);
builder.InsertHtml(headerHtml);
builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);
// footerHtmlString = footerHtmlString + "Page: ($p of $P ) “;
builder.InsertHtml(footerHtmlString);
// Add fields for current page number
builder.InsertField(“PAGE”, “”);
// Add any custom text
builder.Write(” / ");
// Add field for total page numbers in document
builder.InsertField(“NUMPAGES”, “”);

// Move back to the main story of the first section.
builder.MoveToDocumentStart();
builder.InsertHtml(bodyHtmlString);
foreach (Table table in doc.GetChildNodes(NodeType.Table, true))

foreach (Cell cell in table.GetChildNodes(NodeType.Cell, true))<o:p></o:p>

{<o:p></o:p>

//call this method if table’s cell is created on the fly<o:p></o:p>

//newly created cell does not have paragraph inside<o:p></o:p>

cell.EnsureMinimum();<o:p></o:p>

foreach (Paragraph para in cell.Paragraphs)<o:p></o:p>

if (!(cell.ParentRow.IsLastRow && para.IsEndOfCell))<o:p></o:p>

para.ParagraphFormat.KeepWithNext = true;<o:p></o:p>

}

wordStream = new MemoryStream();
builder.Document.Save(wordStream, SaveFormat.Doc);
return wordStream;
}

change Input Htmlbodyhtml and output.doc as an attachment .Please suggest me may I have do some modification in code or html file.

Regards,
Goutam Roy
Cognizant Technology Solutions
Ph:+91 9836765816
Hi Goutam,

Thanks for your inquiry. We have tested the scenario and have managed to reproduce the same issue at our side. For the sake of correction, we have logged this problem in our issue tracking system as WORDSNET-13003. You will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Hi Tahir,


Thanks for your reply.
I have fixed the use just using one one wrapper and inside this
using

in body html. Now it is working properly.


Regards,
Goutam Roy
9836765816
Hi Goutam,

Thanks for your feedback. It is nice to hear from you that your problem has been solved. We will close this issue as 'Not a bug'. Please let us know if you have any more queries.

HI Tahir,


Thanks for assist. I faced another three other problem

1. Header and footer are faded in the output word document.If I click on header then it become prominent. I want to made header and footer prominent.
2. Page no coming in footer but one extra cell is added in footer. I don’t want to add it extra tr in footer rather I want to show it in existing footer.
3.Can we embed future-std-book font in word if future-std-book is not installed in system

The header, footer body html and output document are attached in the previous post.
Please suggest how do I implement the same.

Regards,
Goutam Roy
Cognizant Technology Solutions

Hi Goutam,

Thanks for your inquiry.
Goutam:
1. Header and footer are faded in the output word document.If I click on header then it become prominent. I want to made header and footer prominent.
Could you please share some more detail about this query? We will then provide you more information on this.

Please note that in MS Word documents the contents of header/footers are little bit fade. When you edit header/footer of document, the contents become prominent.
Goutam:
2. Page no coming in footer but one extra cell is added in footer. I don't want to add it extra tr in footer
In your shared output document, the page number is under table. No extra cell is added in the footer.

Please manually create your expected Word document using Microsoft Word. We will investigate how you want your final Word output be generated like. We will then provide you more information on this along with code.
Goutam:
3.Can we embed future-std-book font in word if future-std-book is not installed in system
You need to install required fonts on your system to get the correct output. Please note that Aspose.Words requires TrueType fonts when rendering documents to fixed-page formats (JPEG, PNG, PDF or XPS). You need to install fonts on the machine where you're converting documents to Pdf. Please refer to the following articles:

How Aspose.Words Uses True Type Fonts
How to Specify True Type Fonts Location

Hi Tahir,


Page number should be displayed in the footer as it is in attached doc.

Regards,
Goutam Roy


Hi Goutam,

Thanks for your inquiry. In your Input_Footer.txt, there is a table with one row. There is no need to add colspan="3" in second cell of row. Please use following code example to get the required output. Hope this helps you.

Document doc = new Document();

DocumentBuilder builder = new DocumentBuilder(doc);

PageSetup ps = builder.PageSetup;

ps.PageWidth = 800;

ps.RestartPageNumbering = true;

builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary);

builder.InsertHtml(File.ReadAllText(MyDir + "Input_Header.txt"));

LoadOptions footerLoadOptions = new LoadOptions();

footerLoadOptions.LoadFormat = LoadFormat.Html;

Document footer = new Document(MyDir + "Input_Footer.txt", footerLoadOptions);

DocumentBuilder fBuilder = new DocumentBuilder(footer);

NodeCollection tables = footer.LastSection.Body.Tables;

if (tables.Count > 0)

{

Table table = (Table)tables[tables.Count - 1];

table.AutoFit(AutoFitBehavior.AutoFitToWindow);

Console.WriteLine(table.LastRow.Cells.Count);

fBuilder.MoveToParagraph(footer.GetChildNodes(NodeType.Paragraph, true).IndexOf(table.LastRow.LastCell.LastParagraph), -1);

}

// Add fields for current page number

fBuilder.InsertField("PAGE", "");

// Add any custom text

fBuilder.Write(" / ");

// Add field for total page numbers in document

fBuilder.InsertField("NUMPAGES", "");

builder.MoveToHeaderFooter(HeaderFooterType.FooterPrimary);

builder.InsertDocument(footer, ImportFormatMode.KeepSourceFormatting);

// Move back to the main story of the first section.

builder.MoveToDocumentStart();

builder.InsertHtml(File.ReadAllText(MyDir + "Input_Body.txt"));

doc.UpdateFields();

doc.Save(MyDir + "Out.docx");