How to find Current Page Number using openxml

Home Forums WordprocessingML How to find Current Page Number using openxml

This topic contains 3 replies, has 3 voices, and was last updated by  Anonymous 3 years, 7 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #7913

    neeleshp
    Participant

    hi Eric,
    1. please help me out in getting the current page number using Open Xml word Processing.
    2. i am getting uneven breaking of string/Sentences/Paragraph from word document when comparing the word document.

    #7914

    Eric White
    Keymaster

    Hi,

    Regarding 1., there is no way to do this. To do this, one would have to build a paginator – layout engine, which would exactly duplicate the internal algorithm of Word. This has not been written, nor is it on the schedule.

    Regarding 2., I don’t understand the question.

    #7915

    neeleshp
    Participant

    Hi,
    Thanks for the prompt response.

    The 2nd Scenerio –
    If we have a bold paragraph (5 lines), while reading the word documents the bold paragraph is breaking into many small string. Is there any way to read entire para in 1 string.

    1st Scenerio –
    If Page number is not possible, then at least section number or para number is possible or not.

    Thanks,
    neeleshp

    #9727

    Anonymous

    0

    Here’s an extension method I made for that :

    public static int GetPageNumber(this OpenXmlElement elem, OpenXmlElement root)
    {
    int pageNbr = 1;
    var tmpElem = elem;
    while (tmpElem != root)
    {
    var sibling = tmpElem.PreviousSibling();
    while (sibling != null)
    {
    pageNbr += sibling.Descendants<LastRenderedPageBreak>().Count();
    sibling = sibling.PreviousSibling();
    }
    tmpElem = tmpElem.Parent;
    }
    return pageNbr;
    }

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.