Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Sun Jan 29, 2023 9:48 am

I am trying to parse a Word document and the information I am looking for should be located on the first page only. Is there any way to get the page number for a paragraph using Spire.doc?

Code: Select all
Spire.Doc.Document document_spire = new Spire.Doc.Document(filename);
               
foreach (Spire.Doc.Section section in document_spire.Sections)
                {
                    //Get Each Paragraph of Section 
                    foreach (Spire.Doc.Documents.Paragraph paragraph in section.Paragraphs)
                    {
                        ...
                        //     /* do some processing with the paragraph */
                        Console.WriteLine("Pagenumber of Paragraph");
                    }
               }


If using Microsoft.Office.Interop.Word in C#, I can do that:
Code: Select all
    private static int GetPageNumberOfRange(Word.Range range)
    {
        return (int)range.get_Information(Word.WdInformation.wdActiveEndPageNumber);
    }

But how to do with Spire.doc?
Thank you!

[email protected]
 
Posts: 2
Joined: Sat Dec 05, 2015 11:14 am

Mon Jan 30, 2023 5:57 am

Hello,

Thanks for your inquiry.
Sorry for that the concept of “Page” does not currently exist in Spire.Doc. Therefore, your requirement can’t be achieved currently. However, our Dev team is working to add the concept of “Page” to our product, once your requirement can be achieved, I’ll inform you in time.

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Mon Jan 30, 2023 2:59 pm

Abel.He wrote:Hello,

Thanks for your inquiry.
Sorry for that the concept of “Page” does not currently exist in Spire.Doc. Therefore, your requirement can’t be achieved currently. However, our Dev team is working to add the concept of “Page” to our product, once your requirement can be achieved, I’ll inform you in time.

Sincerely
Abel
E-iceblue support team

Thank you!

[email protected]
 
Posts: 2
Joined: Sat Dec 05, 2015 11:14 am

Tue Jan 31, 2023 1:27 am

You're welcome! :D

Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Tue May 16, 2023 9:23 am

Hello,


Thanks for your patient waiting!
Glad to inform you that we just released Spire.Doc 11.5.6 which achieve the “page” concept.
Please download the new version from the following links to test. And I put relevant code below for your reference.

Website download link: https://www.e-iceblue.com/Download/down ... t-now.html
Nuget download link: https://www.nuget.org/packages/Spire.Doc/11.5.6

Code: Select all
Document doc = new Document();
             doc.LoadFromFile(@"../../data/在线编辑之快问快答.docx", FileFormat.Docx);
             FixedLayoutDocument layoutDoc = new FixedLayoutDocument(doc);

             // Access to the line of the first page and print to the console.
             FixedLayoutLine line = layoutDoc.Pages[0].Columns[0].Lines[0];

             StringBuilder stringBuilder = new StringBuilder();
             stringBuilder.AppendLine("Line: " + line.Text);

             // With a rendered line, the original paragraph in the document object model can be returned.
             Paragraph para = line.Paragraph;

             stringBuilder.AppendLine("Paragraph text: " + para.Text);

             // Retrieve all the text that appears on the first page in plain text format (including headers and footers).
             string pageText = layoutDoc.Pages[0].Text;
             stringBuilder.AppendLine(pageText);

             // Loop through each page in the document and print the count of the lines appear on each page.
             foreach (FixedLayoutPage page in layoutDoc.Pages)
             {
                 LayoutCollection<LayoutElement> lines = page.GetChildEntities(LayoutElementType.Line, true);
                 stringBuilder.AppendLine("Page " + page.PageIndex + " has " + lines.Count + " lines.");
             }

             // This method provides a reverse lookup of layout entities for any given node
             // (except runs and nodes in the header and footer).
             stringBuilder.AppendLine("The lines of the first paragraph:");
             foreach (FixedLayoutLine paragraphLine in layoutDoc.GetLayoutEntitiesOfNode(
                 ((Section)doc.FirstChild).Body.Paragraphs[0]))
             {
                 stringBuilder.AppendLine(paragraphLine.Text.Trim());
                 stringBuilder.AppendLine(paragraphLine.Rectangle.ToString());
             }
             File.WriteAllText(@"../../output/page.txt", stringBuilder.ToString());


Sincerely
Abel
E-iceblue support team
User avatar

Abel.He
 
Posts: 1010
Joined: Tue Mar 08, 2022 2:02 am

Return to Spire.Doc

cron