PDFファイルから画像を削除する

Contents
[ ]

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

PDFファイルから画像を削除するには:

  1. Documentオブジェクトを作成し、入力PDFファイルを開きます。
  2. DocumentオブジェクトのPagesコレクションから画像を保持しているPageを取得します。
  3. 画像は、ページのResourcesコレクションにあるImagesコレクションに保持されています。
  4. ImagesコレクションのDeleteメソッドを使用して画像を削除します。
  5. DocumentオブジェクトのSaveメソッドを使用して出力を保存します。

次のコードスニペットは、PDFファイルから画像を削除する方法を示しています。

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

    // Open PDF document
    using (var document = new Aspose.Pdf.Document(dataDir + "DeleteImages.pdf"))
    {
        // Delete a particular image
        document.Pages[1].Resources.Images.Delete(1);

        // Save PDF document
        document.Save(dataDir + "DeleteImages_out.pdf");
    }
}