Здесь мы покажем Вам, как разделить документ DOCX по страницам в DOCX/HTML формат.
Полный код
using System.IO;
using SautinSoft.Document;
namespace Example
{
class Program
{
static void Main(string[] args)
{
SplitDocumentByPages();
}
/// <summary>
/// Loads a document and split it by separate pages. Saves the each page into DOCX/HTML format.
/// </summary>
/// <remarks>
/// Details: https://sautinsoft.com/products/document/help/net/developer-guide/split-docx-document-by-pages-in-docx-format-net-csharp-vb.php
/// </remarks>
static void SplitDocumentByPages()
{
string filePath = @"..\..\example.docx";
DocumentCore dc = DocumentCore.Load(filePath);
string folderPath = Path.GetFullPath(@"Result-files");
DocumentPaginator dp = dc.GetPaginator();
for (int i = 0; i < dp.Pages.Count; i++)
{
DocumentPage page = dp.Pages[i];
Directory.CreateDirectory(folderPath);
// Save the each page to PDF format.
page.Save(folderPath + @"\Page - " + i.ToString() + ".docx", SaveOptions.DocxDefault);
}
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo(folderPath) { UseShellExecute = true });
}
}
}
Imports System
Imports System.IO
Imports SautinSoft.Document
Module Sample
Sub Main()
SplitDocumentByPages()
End Sub
''' <summary>
''' Loads a document and split it by separate pages. Saves the each page into DOCX/HTML format.
''' </summary>
''' <remarks>
''' Details: https://sautinsoft.com/products/document/help/net/developer-guide/split-docx-document-by-pages-in-docx-format-net-csharp-vb.php
''' </remarks>
Sub SplitDocumentByPages()
Dim filePath As String = "..\example.docx"
Dim dc As DocumentCore = DocumentCore.Load(filePath)
Dim folderPath As String = Path.GetFullPath("Result-files")
Dim dp As DocumentPaginator = dc.GetPaginator()
For i As Integer = 0 To dp.Pages.Count - 1
Dim page As DocumentPage = dp.Pages(i)
Directory.CreateDirectory(folderPath)
' Save the each page to PDF format.
page.Save(folderPath & "\Page - " & i.ToString() & ".docx", SaveOptions.DocxDefault)
Next i
System.Diagnostics.Process.Start(New System.Diagnostics.ProcessStartInfo(folderPath) With {.UseShellExecute = True})
End Sub
End Module
Если вам нужен пример кода или у вас есть вопрос: напишите нам по адресу [email protected] или спросите в онлайн-чате (правый нижний угол этой страницы) или используйте форму ниже: