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.

Mon Dec 20, 2021 9:29 am

Is there any way to remove a specific page from .docx document with Spire.Doc?

Kazax_Kazax
 
Posts: 13
Joined: Tue Nov 30, 2021 4:58 pm

Mon Dec 20, 2021 9:43 am

Hello,

Thanks for your inquiry!

Kindly note that according to the Microsoft Word standards, the Word document is a fluid typesetting method, and this leads that there is no “page” element in the Word structure. We follow MS Word standards, therefore, our Spire.Doc cannot delete the content by page now, hope you can understand.

We would try to support this feature in future version, but I am afraid we cannot support them in short time. Once this feature is complete, we will inform you ASAP.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Mon Dec 20, 2021 9:49 am

Thank you for answer
But as far as I know Spire.Doc supports converting documents to images by page numbers. So it have mechanic to calculate place of a particular element on a page.

Kazax_Kazax
 
Posts: 13
Joined: Tue Nov 30, 2021 4:58 pm

Mon Dec 20, 2021 10:23 am

Hello,

Thanks for your reply.

As I mentioned before, the Word document is a fluid typesetting method. When you use our Spire.Doc converts Word to image, we only calculated the position of each element, then draw them with this fixed position to the image. But if you remove the contents, we need to recalculate the layout of all the remaining content based on the fluid layout. And we need more time to develop it.

Once this feature is complete, we will inform you ASAP.

Sincerely,
Marcia
E-iceblue support team
User avatar

Marcia.Zhou
 
Posts: 858
Joined: Wed Nov 04, 2020 2:29 am

Tue May 16, 2023 6:11 am

Hi,

Thanks for your patience.
Glad to inform you that we just released Spire.Doc 11.5.6 hotfix, which has supported manipulating pages, such as retrieving page content and its coordinates. Please see the following code for reference.
Code: Select all
Document doc = new Document();
doc.LoadFromFile(inputFile, 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 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("page.txt", stringBuilder.ToString());

Please refer to our official website for more updated content introduction: https://www.e-iceblue.com/news/spire-doc/Spire.Doc-11.5.6-supports-adding-charts.html
Download links:
Website: https://www.e-iceblue.com/Download/download-word-for-net-now.html
Nuget: https://www.nuget.org/packages/Spire.Doc/11.5.6

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 999
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.Doc