Is there a way to sense that a table is to large to fit on a single page. By to large, i mean to many columns?
I would like to figure out if the table won’t fit because its width is to great. If i know that how can i switch just that page to landscape?
Thanks for your inquiry. Please attach your input Word document here for our reference. We will provide you more information about your query along with code.
See attached example for code example.
I want to be able to switch any page to landscape if the table doesn’t fit on a page in portrait mode. For example, look at “t6” table in the attached pdf. I realize that there are to many columns to even fit on landscape, but i would at least like to switch the orientation of the page.
The pdf example didn’t upload, you can also get it here -
Thank you for your help ahead of time.
Thanks for your inquiry. In your case, I suggest you please use the LayoutEnumerator.Rectangle property to get the position of paragraph inside the last cell of a row. This property return the bounding rectangle of the current entity relative to the page top left corner (in points).
Please use the following code snippet before saving the final output document. Hope this helps you. Please let us know if you have any more queries.
''doc is document object
Dim layoutCollector As New Aspose.Words.Layout.LayoutCollector(doc)
Dim layoutEnumerator As New Aspose.Words.Layout.LayoutEnumerator(doc)
For Each section As Section In doc.Sections
For Each row As Aspose.Words.Tables.Row In section.GetChildNodes(NodeType.Row, True)
Dim cell As Aspose.Words.Tables.Cell = row.Cells(row.Cells.Count - 1)
Dim renderObject = layoutCollector.GetEntity(cell.FirstParagraph)
layoutEnumerator.Current = renderObject
Dim location As System.Drawing.RectangleF = layoutEnumerator.Rectangle
If section.PageSetup.PageWidth < location.X Then
section.PageSetup.Orientation = Orientation.Landscape
I am having a issue with the example above turning each page to landscape. This is most likely due to one section for the entire document. Do i have to insert a new section for every table? I tried to insert a section for every table and that sections body is null.
What is the best approach?
Thank you for your help.
for your inquiry. In this case, you need to insert section break after each table and change the page orientation. Please use the following code snippet to insert the section break after each table. Hope this helps you. Please let us know if you have any more queries.
Dim builder As New DocumentBuilder(doc)
For Each table As Aspose.Words.Tables.Table In doc.GetChildNodes(NodeType.Table, True)
Dim para = New Paragraph(doc)
Getting closer. I attached a new solution. It seems that the continuous page break isn’t working. For some reason it puts a hard page break in. In the solution I colored the paragraphs so that I could see which paragraph was where and where the page break would occur.
Any help would be appreciated.
for your inquiry. This is the expected behavior of Aspose.Words. Please note that Aspose.Words mimics the same behavior as MS Word does. If you insert the section break (continues) after the table and change the page orientation using MS Word, you will get the same output.
Please let us know if you have any more queries.