プログラムでPDFを分割する

ライブ例

Aspose.PDF Splitterは、プレゼンテーション分割機能がどのように機能するかを調査できるオンラインの無料Webアプリケーションです。

Aspose Split PDF

このトピックでは、C#を使用して.NETアプリケーション内でPDFページを個別のPDFファイルに分割する方法を示します。C#を使用してPDFページを単一ページのPDFファイルに分割するには、以下の手順に従うことができます。

  1. DocumentオブジェクトのPageCollectionコレクションを介してPDFドキュメントのページをループします。
  2. 各イテレーションで、新しいDocumentオブジェクトを作成し、空のドキュメントに個別のPageオブジェクトを追加します。
  3. Saveメソッドを使用して新しいPDFを保存します。

以下のコードスニペットは、Aspose.PDF.Drawingライブラリでも動作します。

PDFを複数のファイルまたは別々のPDFに分割する

以下のC#コードスニペットは、PDFページを個別のPDFファイルに分割する方法を示しています。

// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void SplitDocument()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_Pages();

    // Open PDF document
    using (var document1 = new Aspose.Pdf.Document(dataDir + "SplitToPages.pdf"))
    {
        int pageCount = 1;

        // Loop through all the pages
        foreach (var page in document1.Pages)
        {
            // Create PDF document
            using (var document2 = new Aspose.Pdf.Document())
            {
                document2.Pages.Add(page);
                // Save PDF document
                document2.Save(dataDir + "Page_" + pageCount + "_out.pdf");
                pageCount++;
            }
        }
    }
}