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

Free Support Forum - aspose.com

Insert PageBreak before footer

Hi. Is there a way to insert pageBreak after or before the footer on each page?
If so, please give an example in C#.

Hi

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

Thanks for your request. If I understand you correctly, you would like to insert PageBreak at the end of each page in your document. Right? Unfortunately, there is no way to determine where page starts or ends using Aspose.Words. MS Word document is flow document and does not contain any information about its layout into lines and pages.

Please provide me more information about your goals and maybe I will be able to help you.

Best regards.

Ok. Here’s the thing. I want to insert a page break at the end/beginning of each page, and I was using the same logic as in this topic:
Inserting pagebreak after table
Here’s my code. Its currently throwing an error. My ultimate goal is to insert page breaks, then split the document using those page breaks. Now, I have set the PageSetUp so that the content gets divided the way I want it to. i.e. Based on ContentWidth and ContentHeight.
DocumentBuilder docBuilder = new DocumentBuilder(doc);
docBuilder.PageSetup.Orientation = Aspose.Words.Orientation.Landscape;
docBuilder.PageSetup.PageWidth = ConvertUtil.PixelToPoint((double)ContentWidth);
docBuilder.PageSetup.PageHeight = ConvertUtil.PixelToPoint((double)ContentHeight);
docBuilder.PageSetup.TopMargin = 0.0;
docBuilder.PageSetup.RightMargin = 0.0;
docBuilder.PageSetup.BottomMargin = 0.0;
docBuilder.PageSetup.LeftMargin = 0.0;
docBuilder.PageSetup.PaperSize = PaperSize.Custom;

// Set to ‘true’ if you want different headers/footers for first, even and odd pages.
docBuilder.PageSetup.DifferentFirstPageHeaderFooter = false;
docBuilder.PageSetup.OddAndEvenPagesHeaderFooter = false;

doc.UpdatePageLayout();
doc.UpdateTableLayout();

foreach (Section sect in doc.Sections)
{
//Loop through all headers/footers
foreach (HeaderFooter hf in sect.HeadersFooters)
{
if (hf.HeaderFooterType == HeaderFooterType.FooterEven ||
hf.HeaderFooterType == HeaderFooterType.FooterFirst ||
hf.HeaderFooterType == HeaderFooterType.FooterPrimary)
{
docBuilder.(hf.HeaderFooterType);
//Start table
Table tab = docBuilder.StartTable();
//Insert one cell into the table
docBuilder.InsertCell();
docBuilder.Write(hf.HeaderFooterType.ToString());

//Specify borders formating
docBuilder.CellFormat.Borders.LineStyle = LineStyle.Single;
docBuilder.CellFormat.Borders.Color = Color.Red;
//Specify cell paddings
docBuilder.CellFormat.TopPadding = 2.85;
docBuilder.CellFormat.BottomPadding = 2.85;
docBuilder.CellFormat.LeftPadding = 2.85;
docBuilder.CellFormat.RightPadding = 2.85;

docBuilder.EndRow();
docBuilder.EndTable();

//Create new paragraph and insert it after table
Paragraph par = new Paragraph(doc);
tab.ParentNode.InsertAfter(par, tab);

//move documentBuilder cursor to the paragraph
docBuilder.MoveTo(par);

//Insert page break
docBuilder.InsertBreak(BreakType.PageBreak);
}
}
return doc;


Hi

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

Thank you for additional information. In your code you are trying to insert PageBreak in the footer. It is impossible to insert PageBreak or SectionBreak in header or footer. It is not allowed in Microsoft Word as well, because there is no sense to have PageBreak inside header or footer.

Best regards.


Yes Alexey. I agree with your comment. I know that’s the problem in my code. But I wanted to know if you can help me insert the pageBreak immediately before or after the footer.
Please help.

Header and footer are no parts of documents body, so there is no way to insert anything before or after header or footer. Also, as I told you earlier, there is no way to determine where page starts or ends, because Word document are flow documents and do not contain any information about its layout into lines and pages.

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

Best regards.