InsertBreak (PAGE_BREAK) inserts a space on the next page

Hi,


When I’m using the builder.insertBreak(BreakType.PAGE_BREAK), the Aspose puts a space on the next page at the first character. Is there any way to not put this space?

public void insertPageBreak(Document document) {
DocumentBuilder builder = new DocumentBuilder(document);
builder.moveTo(document.getLastSection().getBody().getLastChild());
builder.insertBreak(BreakType.PAGE_BREAK);
}

Thanks
Regards
Hi Manuel,

Thanks for your inquiry. Please note that Aspose.Words mimics the same behavior as MS Word does.

Could you please attach your input and expected output Word documents here for our reference? We will then provide you more information about your query along with code.

Hi,


The attachment file QRCodeTemplate is a word template that I use to export a bulk of issues. The attachment file QRCodeTemplate_EXPORT is the result right now. As you can see, the first character of page 2 and page 3 is a space, the template doesn’t have that space. I’m just using the builder.insertBreak(BreakType.PAGE_BREAK) like I said on the first post.

When I’m processing the issues, I make a copy of the document (template), after that I process the document and finally I append the processed document to the end of the target document. Something like this:

if (condition) {
insertPageBreak(docTarget);
}

Document docProcessing = (Document) docTemplate.deepClone(true);
docProcessing = staticProcessor.process(docProcessing, processParameters);
docTarget.appendDocument(docProcessing, ImportFormatMode.KEEP_SOURCE_FORMATTING);


public void insertPageBreak(Document document) {
DocumentBuilder builder = new DocumentBuilder(document);
builder.moveTo(document.getLastSection().getBody().getLastChild());
builder.insertBreak(BreakType.PAGE_BREAK);
}


Curiously, if I use the builder.insertBreak(BreakType.SECTION_BREAK_NEW_PAGE) it works fine, but I need to use the BreakType.PAGE_BREAK.


Any idea?

Thanks
Best Regards

Hi Manuel,

Thanks for sharing the document. You are using appendDocument method. So, the output document should have section break. The shared output document does not contain section break.

We have tested the scenario by using insertPageBreak method and have not found the shared issue.

In case you are using older version of Aspose.Words, we suggest you please use Aspose.Words for Java 16.4.0. If you still face problem, please create a standalone Java application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing. We will investigate the issue on our side and provide you more information.