We are currently in the process of evaluating Aspose.PDF for Python via .NET for a critical use case within our organization. Our specific objective is to compress millions of PDF documents, and we are using a temporary license for testing purposes on sample files. However, we have encountered some technical difficulties during our evaluation process. The issues we are facing is in compressing the image size within the pdf using “image_compression_options” class, refer to error screenshot. The testing code is run in GCP workbench and Python 3.10.12 Notebook and source pdf files are being fetch from the bucket within the GCP environment.
code:
for blob in blobs:
if blob.name.endswith('.pdf'):
# Download the PDF file from the source bucket
input_blob = source_bucket.blob(blob.name)
input_data = input_blob.download_as_string()
# Creating a BytesIO buffer to store the compressed PDF
compressed_pdf_buffer = BytesIO()
# Loading the PDF from input_data
pdf_document = ap.Document(BytesIO(input_data))
# Creating an object of OptimizationOptions class
pdfoptimize_options = ap.optimization.OptimizationOptions()
# Enabling image compression
#RuntimeError: Prox error(NotImplementedException): Not supported image type
pdfoptimize_options.image_compression_options.compress_images = True
# Setting the image quality
pdfoptimize_options.image_compression_options.image_quality = 10
# Compressing PDF
pdf_document.optimize_resources(pdfoptimize_options)
# Saveing the compressed PDF to the BytesIO buffer
pdf_document.save(compressed_pdf_buffer)
# Defining the output path in the destination bucket
output_path = f"{destination_folder_name}/com11_{os.path.basename(blob.name)}"
# Uploading the compressed PDF from the BytesIO buffer
output_blob = destination_bucket.blob(output_path)
output_blob.upload_from_file(compressed_pdf_buffer, content_type='application/pdf')
print(f"PDF '{blob.name}' compressed and saved t'{destination_bucket_name}/dll_{output_path}'.")
We look forward to your response and appreciate your prompt attention to this matter
AsposeError.PNG (38.8 KB)