Python을 사용하여 PDF 파일에서 이미지 삭제하기
Contents
[
Hide
]
문서에서 불필요한 그래픽을 제거하거나, PDF 크기를 줄이거나, 민감한 시각적 콘텐츠를 정리해야 할 때 이 페이지를 사용하십시오.
PDF 파일에서 이미지 삭제
다음 단계를 사용하여 페이지에서 이미지 하나를 삭제합니다.
- 를 사용하여 소스 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)