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

Free Support Forum - aspose.com

Remove header/footer in a document when it is appended to another

Hi,
I have multiple documents appended. While I’m doing this, I created a blank page (intentionally left blank page) and append it to another document. I don’t want to have any footer or header in this blank document, but the other document has a footer and header. For some reason, when I append the blank document to the other, the footer and the header are inherited as well. But I don’t want this header/footer in the blank page. Please see my code (java):

/**********CREATE A BLANK DOC (blank page) WITH ONE LINE OF MESSAGE***/
Document blankDocument = new Document();
blankDocument.removeAllChildren();

// Create a new section node.
Section section = new Section(blankDocument);

// Append the section to the document.
blankDocument.appendChild(section);

// Lets set some properties for the section.
section.getPageSetup().setSectionStart(SectionStart.NEW_PAGE);
section.getPageSetup().setPaperSize(PaperSize.LETTER);
section.getPageSetup().setVerticalAlignment(PageVerticalAlignment.CENTER);
section.getPageSetup().setDifferentFirstPageHeaderFooter(false);
section.getPageSetup().setOddAndEvenPagesHeaderFooter(false);

// The section that we created is empty, lets populate it. The section needs at least the Body node.
Body body = new Body(blankDocument);
section.appendChild(body);

// The body needs to have at least one paragraph.
Paragraph para = new Paragraph(blankDocument);
body.appendChild(para);

// Paragraph formatting
para.getParagraphFormat().setStyleName("Normal");
para.getParagraphFormat().setAlignment(ParagraphAlignment.CENTER);

// Create a new run of text and add it to our paragraph.
Run run = new Run(blankDocument);
run.setText("This Page intentionallly left blank.");
run.getFont().setBold(true);
run.getFont().setNameAscii("Arial");
para.appendChild(run);

/**************NOW APPEND THIS TO A DOCUMENT WHICH HAS FOOTER/HEADER***/
// buildDocument is a document with a header/footer.
buildDocument.appendDocument(blankDocument, importFormatMode.KEEP_SOURCE_FORMATTING);

Now the whole document (buildDocument) after this code has footer/header. Can I have the blank page without this header/footer?

Thanks
Michelle

Hi
Thanks for your request. Just add the following line to your code:

section.getHeadersFooters().linkToPrevious(false);

Hope this helps.
Best regards.