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

Free Support Forum - aspose.com

Merged Cells, Don't Allow Rows to Break Across Pages

Hello!

I’m using Aspose.Words for Java to make a report with a table like the one below:

3.jpg (92.0 KB)

What I expect to happen is this:
1.jpg (96.2 KB)

Instead, I get this:
2.jpg (108.7 KB)

I’ve seen this help document, but it doesn’t meet my needs. https://docs.aspose.com/words/java/keeping-tables-and-rows-from-breaking-across-pages/
Is there any way for Aspose to keep the merged cells together?

@satcfj

To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word document.
  • Please attach the output Word file that shows the undesired behavior.
  • Please attach the expected output Word file that shows the desired behavior.
  • Please create a simple Java application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

this is words what you want.MyDocTest.zip (2.0 MB)
this is source code. main method at path:MyDocTest/src/main/java/com/aspose/words/examples/linq/DocTestMain.java
归档.zip (482.0 KB)

@satcfj

In your first post, the reported issue was related to merged cells. However, the code of DocTestMain.java is related to removing empty pages.

You are using PageSplitter code to split the document’s pages. We suggest you please use Document.extractPages method instead of PageSplitter to get the correct result. Please use Document.extractPages method to extract all pages of Word document. Once you have extracted all pages, join the extracted documents (pages) which are not empty.

If your issue is different, please share some more detail along with page numbers of problematic sections of output document. We will investigate the issue and provide you more information on it.

Sorry!The question is not the same.I just want to delete empty pages by determining whether the node has content or not.but when i use this code:

for (int i = 0; i < pages; i++) {
            String pageText = "";
            ArrayList<Node> nodes = getNodesByPage(i, doc);
            for (int j = 0; j < nodes.size(); j++) {
                Node node = nodes.get(j);
                pageText += node.toString(SaveFormat.TEXT).trim();
            }

           System.out.println(i + " ==========>>>> " + pageText);
           // 

            // Remove the page if the node content of the page is empty。
            if (pageText.equals("")) {
                for (Node node : nodes) {
                    node.remove();
                }
            }
        }

cant not remove empty page.

@satcfj

Please use following code example to remove the empty pages from the Word document. Hope this helps you.

Document doc = new Document(MyDir + "input.docx");

// A List will hold blank page numbers
ArrayList<Integer> emptyPageNumbers = new ArrayList<Integer>();
emptyPageNumbers.add(-1);

// Extract each page as a separate Word document
int totalPages = doc.getPageCount();
for (int i = 0; i < totalPages; i++)
{
    Document pageDoc = doc.extractPages(i, 1);

    // Get text representation of this Page
    String textOfPage = "";
    for (Section section : pageDoc.getSections())
        // Lets not consider the content of Headers and Footers
        textOfPage = textOfPage + section.getBody().toString(SaveFormat.TEXT);

    // if text_of_Page is empty then Page is blank
    if (textOfPage.trim().length() == 0)
        emptyPageNumbers.add(i);
}
emptyPageNumbers.add(totalPages);

// Concatenate documents with non-empty pages again
Document final_Document = (Document)doc.deepClone(false);
final_Document.removeAllChildren();

for (int i = 1; i < emptyPageNumbers.size(); i++)
{
    int index = (int)emptyPageNumbers.get(i - 1) + 1;
    int count = (int)emptyPageNumbers.get(i) - index;

    if (count > 0)
        final_Document.appendDocument(doc.extractPages(index, count), ImportFormatMode.KEEP_SOURCE_FORMATTING);
}

final_Document.save(MyDir + "output.docx"); 

this code is no solution.here is input document input_word.docx (132.4 KB)
and why the output document is the same as input document?
i try to use code to each page is saved as a document and split out the empty page:

private static void spliterPagesByNumber(Document document) throws Exception {
        Document final_Document = (Document) document.deepClone(false);
        for (int i = 0; i < document.getPageCount(); i++) {
            Document doc = document.extractPages(i, 1);
            doc.save(dataDir + i + "result.docx");
            //final_Document.appendDocument(doc, ImportFormatMode.KEEP_SOURCE_FORMATTING);
        }
 //final_Document.save(dataDir + "result.docx");
    }

has another qusetion:
The first page of content After this code is executed, the content becomes two pages.page 0.docx (26.6 KB)
page 1.docx (25.9 KB)
and empty page in the output document is missing!

please help me.
thanks!!!

@satcfj

Please note that Aspose.Words requires TrueType fonts when rendering document to fixed-page formats (JPEG, PNG, PDF or XPS) or calculating pages. You need to install fonts that are used in your document on the machine where you are extracting the document’s pages.
Using TrueType Fonts

You can use following code example to get the missing fonts notification for your document.

Document doc = new Document(MyDir + "input_word.docx");

doc.setWarningCallback(new IWarningCallback() {
    @Override
    public void warning(WarningInfo warningInfo) {
        if (WarningType.FONT_SUBSTITUTION == warningInfo.getWarningType()) {
            System.out.println(warningInfo.getDescription());
        }
    }
});

doc.save(MyDir + "21.5.pdf");

Moreover, we have not found any empty page in your input Word document.