Mismatch in page number while converted to pdf

Hi,

I am updating a document file by replacing a special word with some content extracted from another document. And then save the document as both Word and PDF. I added a blank page between two pieces of content. in Word document, it is showing but pdf is not taking the first blank page. I am attaching the input, output, template file, and the sample code.src.zip (142.1 KB)

Please help me to solve this issue. It’s very critical on our side

Thank you

@Gptrnt The problem occur because page break is inserted as hidden. If render the document with showing hidden content, the page break is rendered:

Document doc = new Document("C:\\Temp\\in.docx");
doc.getLayoutOptions().setShowHiddenText(true);
doc.save("C:\\Temp\\out_with_hidden_text.pdf");

Please try modifying your code like this to make sure page break is not inserted as hidden:

builder.getFont().setHidden(false);
builder.writeln();
builder.insertBreak(BreakType.PAGE_BREAK);

Hi,
I have updated the code with the solution you provided.

builder.getFont().setHidden(false);
builder.writeln();
builder.insertBreak(BreakType.PAGE_BREAK);

But still, it is not working for me

Thank you

@Gptrnt This work fine in the latest 23.9 version. As I can see you are using an old 21.1 version of Aspose.Words. I have made it work with 21.1 version using the following code:

builder.writeln();
builder.getFont().setHidden(false);
builder.insertBreak(BreakType.PAGE_BREAK);
builder.writeln();