Remove Attachments
Contents
[
Hide
]
PDFs may contain attachments such as documents, images, or other files. There are scenarios where you need to clean a PDF of all attachments for security, privacy, or distribution purposes. Using PdfContentEditor, you can programmatically remove all embedded attachments in a document.
- Create the PdfContentEditor object.
- Bind the input PDF.
- Delete All Attachments.
- Save the updated Document.
import aspose.pdf.facades as pdf_facades
import aspose.pydrawing as apd
from io import BytesIO
import sys
from os import path
sys.path.append(path.join(path.dirname(__file__), ".."))
from config import set_license, initialize_data_dir
def remove_attachments(infile, outfile):
# Create PdfContentEditor object
content_editor = pdf_facades.PdfContentEditor()
# Bind document to PdfContentEditor
content_editor.bind_pdf(infile)
# Remove all attachments from document
content_editor.delete_attachments()
# Save updated document
content_editor.save(outfile)