Here’s a code snippet reproducing this:
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.writeln("First line");
builder.getParagraphFormat().setKeepWithNext(true);
builder.writeln("Table name");
builder.getRowFormat().setAllowBreakAcrossPages(false);
builder.startTable();
for (int i = 0; i < 15; i++) {
builder.insertCell();
builder.writeln("Line1");
builder.writeln("Line2");
builder.writeln("Line3");
builder.endRow();
}
builder.insertCell();
builder.writeln("Line1");
builder.getParagraphFormat().setKeepWithNext(false);
builder.endTable();
doc.updatePageLayout();
log.info("Page count in memory: {}", doc.getPageCount());
try (FileOutputStream fos = new FileOutputStream(OUTPUT_PATH)) {
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions();
saveOptions.setSaveFormat(SaveFormat.DOCX);
saveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT);
doc.save(fos, saveOptions);
}
When I open exported file with word, I get 4 pages with both paragraphs on their own pages and then the table on pages 3 and 4:
Screen Shot 2022-05-03 at 16.43.54.png (2.4 KB)
But in memory layout of the document is 3 pages and if visualized in word probably looks like this:
aspose-in-memory.png (2.3 KB)
I’m aware that this is happening because Aspose is using ECMA_376_2006 in memory. But its important for us to have the same layout in memory and PDF exports as you would get after you open the saved file with ISO_29500_2008_STRICT, so two questions:
- Is it possible to define compliance when starting from a blank document, so that in this example we get 4 pages in memory layout?
- Is there a way to build the document so that its 3 pages and looks exactly how it does in aspose after its saved with ISO_29500_2008_STRICT?
By the way, the objective of ours is to keep tables from breaking as described in: Work with Columns and Rows in Java|Aspose.Words for Java