Hi,
Do you know if there is a way to calculate when to put pagebreaks properly ?
This should be a discretional action done by the user who is watching the
word document but I was figuring out to do something like this:
- Get position of a specific paragraph ( for istances Heading Paragraph ).
- If the position is over 80% of the page starting from top I insert a pagebreak
Is is possible to do it with ASPOSE.Word ?
So what I just need is my opinion is a function to calculate an object position in a page
@nvezzoli,
Please check Aspose.Words.Layout namespace that provides classes (such as LayoutCollector & LayoutEnumerator) that allow to access information such as on what page and where on a page particular document elements are positioned. For example, to get position of a Paragraph marker, use the following code:
Document doc = new Document("C:\\temp\\input.docx");
LayoutCollector collector = new LayoutCollector(doc);
LayoutEnumerator enumerator = new LayoutEnumerator(doc);
Paragraph targetPara = doc.FirstSection.Body.FirstParagraph;
enumerator.Current = collector.GetEntity(targetPara);
// 72 points equal to 1 inch
Console.WriteLine("This Paragraphs ends at ({0}, {1})", enumerator.Rectangle.Left, enumerator.Rectangle.Top);
// to determine the page height and width
Console.WriteLine(targetPara.ParentSection.PageSetup.PageHeight + " " + targetPara.ParentSection.PageSetup.PageWidth);
// to insert explicit page break
DocumentBuilder builder = new DocumentBuilder(doc);
builder.MoveTo(targetPara);
builder.InsertBreak(BreakType.PageBreak);
1 Like