NodeCollection paragraphs = doc.getChildNodes(NodeType.PARAGRAPH, true);
for (Paragraph para : (Iterable<Paragraph>) paragraphs)
{
// If the paragraph has a page break set before, then clear it.
if (para.getParagraphFormat().getPageBreakBefore()) {
para.getParagraphFormat().setPageBreakBefore(false);
}
// Check all runs in the paragraph for page breaks and remove them.
for (Run run : para.getRuns()) {
if (run.getText().contains(ControlChar.PAGE_BREAK)) {
run.setText(run.getText().replace(ControlChar.PAGE_BREAK, ""));
}
}
}
Document doc = new Document("input.docx");
NodeCollection paragraphs = doc.getChildNodes(NodeType.PARAGRAPH, true);
for (Paragraph para : (Iterable<Paragraph>) paragraphs)
{
// If the paragraph has a page break set before, then clear it.
if (para.getParagraphFormat().getPageBreakBefore()) {
para.getParagraphFormat().setPageBreakBefore(false);
}
// Check all runs in the paragraph for page breaks and remove them.
for (Run run : para.getRuns()) {
if (run.getText().contains(ControlChar.PAGE_BREAK)) {
run.setText(run.getText().replace(ControlChar.PAGE_BREAK, ""));
}
}
}
doc.save("output.pdf");