Как удалить указанную страницу в документе с помощью C# и .NET


    В этом примере кода показано, как удалить определенную страницу в документе. В этом в этом случае мы удалим second перелистайте и сохраните документ в формате DOCX. Также применимо к документам в формате PDF.


Полный код

using SautinSoft.Document;
using System;

namespace Sample
{
    class Program
    {
        static void Main(string[] args)
        {
            // Get your free 30-day key here:   
            // https://sautinsoft.com/start-for-free/

            DeleteSpecifiedPageInDocument();       
        }
        /// <summary>
        /// How to delete the specified page in the document.
        /// </summary>
        /// <remarks>
        /// Details: https://sautinsoft.com/products/document/help/net/developer-guide/from-customers-delete-specified-page-in-document-net-csharp-vb.php
        /// </remarks>
        public static void DeleteSpecifiedPageInDocument()
        {
            string inpFile = @"..\..\..\example.docx";
            string outFile = @"result.docx";
            
			// Load a document into DocumentCore.
            DocumentCore dc = DocumentCore.Load(inpFile);

            // Divide the document into separate pages.
            DocumentPaginator dp = dc.GetPaginator();

            // Delete page number two.
            dp.Pages[1].Content.Delete();
            
			 // Save our result as a DOCX file.
            dc.Save(outFile);

            // Open the result for demonstration purposes.
            System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(outFile) { UseShellExecute = true });
        }
    }
}

Download

Imports SautinSoft.Document
Imports System

Namespace Sample
	Friend Class Program
		Shared Sub Main(ByVal args() As String)
			DeleteSpecifiedPageInDocument()
		End Sub
                ''' Get your free 30-day key here:   
                ''' https://sautinsoft.com/start-for-free/
		''' <summary>
		''' How to delete the specified page in the document.
		''' </summary>
		''' <remarks>
		''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/from-customers-delete-specified-page-in-document-net-csharp-vb.php
		''' </remarks>
		Public Shared Sub DeleteSpecifiedPageInDocument()
			Dim inpFile As String = "..\..\..\example.docx"
			Dim outFile As String = "result.docx"

			' Load a document into DocumentCore.
			Dim dc As DocumentCore = DocumentCore.Load(inpFile)

			' Divide the document into separate pages.
			Dim dp As DocumentPaginator = dc.GetPaginator()

			' Delete page number two.
			dp.Pages(1).Content.Delete()

			 ' Save our result as a DOCX file.
			dc.Save(outFile)

			' Open the result for demonstration purposes.
			System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(outFile) With {.UseShellExecute = True})
		End Sub
	End Class
End Namespace

Download


Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу [email protected] или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже:



Вопросы и предложения всегда приветствуются!

Мы разрабатываем компоненты .Net с 2002 года. Мы знаем форматы PDF, DOCX, RTF, HTML, XLSX и Images. Если вам нужна помощь в создании, изменении или преобразовании документов в различных форматах, мы можем вам помочь. Мы напишем для вас любой пример кода абсолютно бесплатно.