Hello team,
I am trying to calculate height and width of splited content control on multiple page and set height and width as a bookmark name and add this bookmark inside content control first child. How can i implement this ?
Document sourceDoc = new Aspose.Words.Document(@"C:\Temp\SourceDoc.docx");
var sdts = outputDoc.GetChildNodes(NodeType.StructuredDocumentTag, true).Where(x => ((Aspose.Words.Markup.StructuredDocumentTag)x).Tag.StartsWith("Rangescop_"));
foreach (Aspose.Words.Markup.StructuredDocumentTag sdt in sdts)
{
CalculateHeightAndWidth(ref outputDoc, sdt.Tag, (Paragraph)sdt.GetChildNodes(NodeType.Paragraph, true).FirstOrDefault(), (Paragraph)sdt.GetChildNodes(NodeType.Paragraph, true).LastOrDefault());
}
outputDoc.Save(@"C:\Temp\OutputDoc.docx", SaveFormat.Docx);
I already have logic for calculate height and width but this logic not working on calculate height and width of splited content control.
This is my function for calculate height and width :
private void CalculateHeightAndWidth(ref Document document, string Tag, Paragraph startParagraph, Paragraph endParagraph)
{
try
{
LayoutCollector LayoutCollector = new LayoutCollector(document);
LayoutEnumerator = new LayoutEnumerator(document)
{
Current = LayoutCollector.GetEntity(startParagraph)
};
while (LayoutEnumerator.Type != LayoutEntityType.Line)
LayoutEnumerator.MoveParent();
//Get the rectangle occuped by the first line of the paragraph.
RectangleF rect1 = LayoutEnumerator.Rectangle;
LayoutEnumerator.Current = LayoutCollector.GetEntity(endParagraph);
while (LayoutEnumerator.Type != LayoutEntityType.Line)
LayoutEnumerator.MoveParent();
RectangleF rect2 = LayoutEnumerator.Rectangle;
//Union of the rectangles is the region occuped by the paragraph.
RectangleF result = RectangleF.Union(rect1, rect2);
Builder.MoveTo(startParagraph);
string temp = "HW_" + Tag.ToString() + "_" + result.Height.ToString().Split('.')[0] + "_" + result.Width.ToString().Split('.')[0];
Builder.StartBookmark(temp);
Builder.EndBookmark(temp);
LayoutCollector.Clear();
document.UpdatePageLayout();
}
catch (Exception e)
{
}
}
SourceDoc.docx (68.9 KB)