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

Free Support Forum - aspose.com

How do I delete a page break?

Hi,
I have a question on deleting a page break. I have a generated document which contains a page break followed by Section Break (new page). I want to delete this page break. How do I do that?

I use a Java version of Aspose.word.

Thanks,
Michelle

Hi<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thanks for your request. Please attach a sample document. I will create sample code for you.

Best regards,

Alexey,
Here is the sample document. Maybe I did not explain well at first. Let me revise my question. How do I remove (or delete) a page without any content. Basically, there is a blank page with header and footer. But its body does not have any content in it. And the break type is PAGE_BREAK not SECTION_BREAK_NEW_PAGE.
Thank you.
Michelle

Hi Michelle,<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

Thank you for additional information. You can try using the following code to remove all page breaks from the document.

//Save document

doc.Save(@"Test063\out.doc");

//Open document

Document doc = new Document("C:\\Temp\\sample.doc");

//Get collection of Runs from the document

NodeCollection runs = doc.getChildNodes(NodeType.RUN, true);

//Loop through all runs

for (int i = 0; i < runs.getCount(); i++)

{

Run run = (Run)runs.get(i);

//Remove PageBreak Character

run.setText(run.getText().replace('\f', ' '));

}

//Save output document

doc.save("C:\\Temp\\out.doc");

Hope this helps.

Best regards.

Thank you so much, Alexey. It works great!