Use the OPENXML SDK to read content by page:
The following content uses wpf+richtextbox+flowdocment display, the test document total 3 pages of content, the picture shows is obtains the first page content, after enclosing the code, as follows:
1 /// <summary>2 ///load Word by page3 /// </summary>4 /// <param name= "Flowdoc" ></param>5 /// <param name= "filename" ></param>6 /// <param name= "page" ></param>7 Public Static voidLOADWORDML ( ThisFlowDocument Flowdoc,stringFileNameintpage)8 {9XElement WordDoc =NULL;Ten Try One { APackage package =package.open (filename); -Uri Documenturi =NewUri ("/word/document.xml", urikind.relative); -PackagePart Documentpart =Package . GetPart (Documenturi); theWordDoc = Xelement.load (NewStreamReader (Documentpart.getstream ())); - } - Catch(Exception) - { +FLOWDOC.BLOCKS.ADD (NewSystem.Windows.Documents.Paragraph (NewSystem.Windows.Documents.Run ("File not found or not in correct format (Word)"))); - return; + } A atXNamespace W ="Http://schemas.openxmlformats.org/wordprocessingml/2006/main"; - - varParagraphs = fromPinchWorddoc.descendants (W +"P") - Selectp; - intPagecount=0; - foreach(varPinchparagraphs) in { - varPagetag = fromSinchP.descendants (W +"Lastrenderedpagebreak")Selects; to if(Pagetag.count () >0) + { -pagecount++; the if(PageCount = =page) * { $ Break;Panax Notoginseng } - } the varstyle = fromSinchP.descendants (W +"PPr") + Selects; A the varFont = ( fromFinchStyle. Descendants (W +"rFonts") + SelectF.firstattribute). FirstOrDefault (); - varSize = ( fromSinchStyle. Descendants (W +"sz") $ SelectS.firstattribute). FirstOrDefault (); $ -System.Windows.Documents.Paragraph par =NewSystem.Windows.Documents.Paragraph (); -System.Windows.Documents.Run r =NewSystem.Windows.Documents.Run (p.value); the if(Font! =NULL) - {WuyiFontfamilyconverter converter =NewFontfamilyconverter (); ther.fontfamily =(System.Windows.Media.FontFamily) converter. ConvertFrom (font. Value); - } Wu if(Size! =NULL) - { AboutR.fontsize =Double. Parse (size. Value); $ } - par. Inlines.add (r); - - flowDoc.Blocks.Add (PAR); A } +}
How does WPF RichTextBox flowdocment implement automatic paging? Two