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

Free Support Forum - aspose.com

Stopping tables from page breaking


I have mocked up a solution using Aspose.Words. In this solution, I am trying to keep tables from page breaking, but it doesn’t seem like its working.

The solution and picture of the report can be found here.

I tried to upload it, but couldn’t for some reason.

I was looking at your Aspose.PDF, but it couldn’t do what i wanted so im not evaluating the Aspose.Words product (which seems to be way more stable).

Any help would be appreciated.

Thank you,


Hi Brandon,

Thanks for your inquiry. I have worked with your sample application and have found that you are creating one big table. Please insert an empty paragraph after creating each table. I have modified your code. Please check the following highlighted code snippet. I have attached the complete code with this post for your kind reference.

Hope this helps you. Please let us know if you have any more queries.

Private Sub addDisciplineAndResults(s As Section)
Dim para = s.NewParagraph
para.NewText("Mammalian Serology", size:=9, bold:=True)
'Add Animals
For a As Integer = 0 To 25 - 1
Dim table = s.NewTable
'Add heading
Dim rowHeading = table.NewRow
rowHeading.NewCell().NewText("Specimen", size:=9, bold:=True)
rowHeading.NewCell().NewText("Test Name", size:=9, bold:=True)
rowHeading.NewCell().NewText("Result", size:=9, bold:=True)
rowHeading.RowFormat.Borders.LineStyle = LineStyle.None
Dim rowAnimal = table.NewRow
Dim aFirstCell = rowAnimal.NewCell()
aFirstCell.NewText(a & "-14 Avain - Galliform / poultry - Checken - Unknown - Juvenile", size:=9)
Dim lastAnimalCell = rowAnimal.NewCell()
SpanCellsInRow(aFirstCell, lastAnimalCell)
For sp As Integer = 0 To 5 - 1
Dim rowSpecimen = table.NewRow
Dim sFirstCell = rowSpecimen.NewCell()
sFirstCell.NewText("Liver - " & sp, size:=9)
rowSpecimen.NewCell().NewText("Test A", size:=9)
rowSpecimen.NewCell().NewText("Approximately 500 ppm", size:=9)
Dim rowSpecimenTestB = table.NewRow
rowSpecimenTestB.NewCell().NewText("Test B", size:=9)
rowSpecimenTestB.NewCell().NewText("Negative", size:=9)
Dim rowSpecimenTestC = table.NewRow
rowSpecimenTestC.NewCell().NewText("Test C", size:=9)
rowSpecimenTestC.NewCell().NewText("> 0 = ayz", size:=9)
para = s.NewParagraph()
End Sub
Public Sub New()
Doc = New Document
' Builder = New DocumentBuilder
Dim currentSection As Section = Doc.FirstSection
currentSection.PageSetup.BottomMargin = InchToPoint(0.5)
currentSection.PageSetup.TopMargin = InchToPoint(0.5)
currentSection.PageSetup.LeftMargin = InchToPoint(0.5)
currentSection.PageSetup.RightMargin = InchToPoint(0.5)
For Each table As Table In Doc.GetChildNodes(NodeType.Table, True)
For Each cell As Cell In table.GetChildNodes(NodeType.Cell, True)
For Each para As Paragraph In cell.Paragraphs
If Not (cell.ParentRow.IsLastRow AndAlso para.IsEndOfCell) Then
para.ParagraphFormat.KeepWithNext = True
End If
Next para
Next cell
End Sub

I checked out your solution and it works when saving to docx, but not when saving to pdf.

I need the end result to be pdf. Why would the resulting word document be different than the pdf, when its all the same code.

a fast answer would be appreciated. I need to find a product for our reporting engine. I spent a week on your pdf suite which has many, many errors, etc. Words so far is looking promising, but need to finish testing.

Thank you,

Hi Brandon,

Thanks for your inquiry.

I have tested the scenario and have managed to reproduce the same issue at my side. For the sake of correction, I have logged this problem in our issue tracking system as WORDSNET-10257. I have linked this forum thread to the same issue and you will be notified via this forum thread once this issue is resolved.

We apologize for your inconvenience.

Thank you. How long does it take to get fixed. This is something that will need fixed before we go live using your product.

Am I correct in assuming saving as pdf should look exactly like docx in all scenarios?

Hi Brandon,

Thanks for your inquiry. I would like
to share with you that issues are addressed and resolved based on first
come first serve basis. Currently, your issue is pending for analysis
and is in the queue. We will update you via this forum thread once there
is any update available on your issue.

Thank you for your patience and understanding.

Hi Brandon,

Thanks for your patience.

It is to inform you that our development team has completed the work on the issue (WORDSNET-10257) and has come to a conclusion that this issue and the undesired behavior you’re observing is actually not a bug in Aspose.Words. So, we have closed this issue as ‘Not a Bug’.

In your code your are creating Cells on the fly. In this case, the newly created cell does not have paragraph inside and that is why the KeepTableFromPageBreak method does not work. Please use the following modified KeepTableFromPageBreak method to get the required output.

Public Shared Sub KeepTableFromPageBreak(t As Table)
For Each cell As Cell In t.GetChildNodes(NodeType.Cell, True)
cell.EnsureMinimum() 'Add this line of code.
For Each para As Paragraph In cell.Paragraphs
If Not (cell.ParentRow.IsLastRow AndAlso para.IsEndOfCell) Then
para.ParagraphFormat.KeepWithNext = True
End If
End Sub

Worked Great! Thank you so much.

Hi Brandon,

Thanks for your feedback. Please feel free to ask if you have any question about Aspose.Words, we will be happy to help you.