wordpress hit counter
Read .docx page by page - WordprocessingML - Formats - OpenXML Developer

Read .docx page by page

Formats

Discussions about working with different Open XML Formats

Read .docx page by page

  • rated by 0 users
  • This post has 4 Replies |
  • 2 Followers
  • using DocumentFormat.OpenXml;

    using DocumentFormat.OpenXml.Packaging;

    I use

    WordprocessingDocument doc = WordprocessingDocument.Open("c:\\word.docx",true);

    Do anyone know how to read document page by page?  Thanks

     

  • Hi.

    Open Xml SDK is for not page layout, which means SDK hardly know "Page break" unless it is explicit.

    But I'm interested in why you want to read it page by page? Is it too large? Is it in server? What are those documents for and who are the target readers? Could you tell me more about your scenario, please?

    I appreciate your efforts and time in advance:)

  • Hello,

    I also need help in this question. Please advise how I can iterate by pages. I need to put some picture in top and bottom parts for all pages. Thanks!

  • Hi Nix,

    Goodol is correct. The Open XML SDK does not provide rendering calculations such as page breaks. However if all you need is to put information at the top and bottom of each page, you can use headers and footers for that. Simply define the header and footer parts that you need, and make sure they are referenced in the section properties element using header/footer reference child elements.

    Hope this helps.

    Jim

  • Hello Jim,

    Thanks for the answer. I can not use header, footer and watermark. I need to put some labels to top and footer for all pages.  I do it so

    IEnumerable<Paragraph> topP = wdDoc.MainDocumentPart.Document.Body.Elements<Paragraph>();

                       bool skip = false;

                       foreach (Paragraph p in topP)

                       {

                           if (!ContainLastRenderedPageBreak(p))

                           {

                               if (!skip)

                               {  

                                   p.Append(runElementFooter.CloneNode(true));

                                   p.Append(runElementHeader.CloneNode(true));

                                   skip = true;

                               }

                           }

                           else skip = false;

                           if (ContainPageBreak(p))

                           {

                               p.Append(runElementFooter.CloneNode(true));

                               p.Append(runElementHeader.CloneNode(true));

                               skip = false;

                           }

                       }

    public bool ContainPageBreak(Paragraph p)

           {

               return p.Elements<Run>().FirstOrDefault(r => r.Elements<Break>().FirstOrDefault(b => b.Type == BreakValues.Page) != null) != null;

           }

           public bool ContainLastRenderedPageBreak(Paragraph p)

           {

               return p.Elements<Run>().FirstOrDefault(r => r.Elements<LastRenderedPageBreak>().FirstOrDefault() != null) != null;

           }

    And its work for me now, but for some documtns bottom label is bad positioning and I don't know why its happen.

    Aleksey

Page 1 of 1 (5 items)