PDFページをプログラムで削除する C#

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

Aspose.PDF for .NETを使用してPDFファイルからページを削除できます。PageCollectionコレクションから特定のページを削除します。

PDFファイルからページを削除

  1. Deleteメソッドを呼び出し、ページのインデックスを指定します。
  2. Saveメソッドを呼び出して、更新されたPDFファイルを保存します。 次のコードスニペットは、C#を使用してPDFファイルから特定のページを削除する方法を示しています。
// For complete examples and data files, visit https://github.com/aspose-pdf/Aspose.PDF-for-.NET
private static void DeletePageFromPdfFile()
{
    // The path to the documents directory
    var dataDir = RunExamples.GetDataDir_AsposePdf_Pages();
    
    // Open PDF document
    using (var document = new Aspose.Pdf.Document(dataDir + "DeleteParticularPage.pdf"))
    {
        // Delete a particular page
        document.Pages.Delete(2);
        // Save PDF document
        document.Save(dataDir + "DeleteParticularPage_out.pdf");
    }
}