WordprocessingDocument doc = WordprocessingDocument.Open("c:\\word.docx",true);
Do anyone know how to read document page by page? Thanks
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:)
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!
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.
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)
skip = true;
else skip = false;
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.