Python を使用して PDF ファイルから画像を削除する
Contents
[
Hide
]
このページは、不要なグラフィックを削除したり、PDF サイズを小さくしたり、文書から機密性の高いビジュアルコンテンツを消去したりする必要がある場合に使用します。
PDF ファイルからの画像の削除
次の手順を使用して、ページから 1 つの画像を削除します。
- ソース PDF を以下のようにロードします。
ap.Document(infile). - ページと画像リソースインデックスを選択します。
- で画像を削除する
resources.images.delete(index). - 更新した PDF を保存します。
import aspose.pdf as ap
def delete_image(infile, outfile):
document = ap.Document(infile)
document.pages[1].resources.images.delete(1)
document.save(outfile)
ページからすべての画像を削除する
この例を使用して、特定のページからすべての画像を削除します。
import aspose.pdf as ap
def delete_all_images_from_page(infile, outfile, page_number):
document = ap.Document(infile)
page = document.pages[page_number]
while len(page.resources.images) != 0:
page.resources.images.delete(1)
document.save(outfile)