Hello,
Pdf and Word files don’t match in case when document has table which has vertical merged cell with long text and “page break before” in next row.
There is an option to save documents in Word with OOXML compliance equals ISO29500:2008 STRICT. There is no compliance in PdfSaveOptions with which save document would work the same way as Word.
Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);
builder.getParagraphFormat().clearFormatting();
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
builder.write("1");
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
builder.write("2");
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
builder.write("3");
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
builder.write("4");
builder.endRow();
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
builder.write("5");
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
builder.write("6");
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.FIRST);
builder.write("Text in merged cells. Text in merged cells. Text in merged cells. Text in merged cells. Text in merged cells. Text in merged cells. Text in merged cells. Text in merged cells. Text in merged cells. Text in merged cells. Text in merged cells. Text in merged cells. Text in merged cells. Text in merged cells. Text in merged cells. Text in merged cells. Text in merged cells.");
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
builder.write("7");
builder.endRow();
builder.getParagraphFormat().clearFormatting();
builder.getParagraphFormat().setPageBreakBefore(true);
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
builder.write("8");
builder.insertCell();
builder.getParagraphFormat().clearFormatting();
builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
builder.write("9");
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.PREVIOUS);
builder.insertCell();
builder.getCellFormat().setVerticalMerge(CellMerge.NONE);
builder.write("10");
builder.endRow();
builder.insertCell();
builder.write("11");
builder.insertCell();
builder.write("12");
builder.insertCell();
builder.write("13");
builder.insertCell();
builder.write("10");
builder.endRow();
builder.endTable();
OoxmlSaveOptions saveOptions = new OoxmlSaveOptions(SaveFormat.DOCX);
saveOptions.setCompliance(OoxmlCompliance.ISO_29500_2008_STRICT);
doc.save("doc.docx", saveOptions);