PPT to PDF in Python: When You Extract the Last Few Pages of a PDF, Their Size Is Too Large

I am using the Aspose.Slides library in Python to convert a PPTX presentation to PDF. This works perfectly; however, when extracting the final pages of the resulting PDF, their size is too large, almost as large as the total size of the PDF. Here is the specific case:

file complete have 437 pages, each page have always 4 image and one title like this image:

complete_file.pdf → 144 MB
page[#1].pdf → 2MB
page[#368].pdf → 118.4 MB
page[#369].pdf → 119.1 MB
page[#437].pdf–> 138 MB
image.jpg (262.3 KB)

I would like to know if it is possible to perform any optimization in the conversion from PPTX to PDF using the Aspose.Slides library, because when this same conversion is done using the PowerPoint application, this does not happen; extracting any page results in a size of at most 2MB. I do not wish to use the alternative of compressing the resulting PDF, as I have seen that other libraries manage to convert the PPTX to PDF without this inconsistency occurring.

CODE USE:

import os
import sys
import aspose.slides as slides
from datetime import datetime
from PyPDF2 import PdfWriter , PdfReader
import array 

BASE_DIR = os.path.dirname(os.path.realpath('__file__'))
INPUT_FOLDER = os.path.join(BASE_DIR, 'Input')
OUTPUT_FOLDER = os.path.join(BASE_DIR,'Output')

pdfpath = OUTPUT_FOLDER
filename = "XXXXXXXXXXX"
pptpath = os.path.join(INPUT_FOLDER, f"{filename}.pptx")
print(OUTPUT_FOLDER)
pdfpath = os.path.join(OUTPUT_FOLDER, f"{filename}.pdf")

input_ppt = slides.Presentation(pptpath)
options = slides.export.PdfOptions()
# Sets the behavior for metafiles
#options.save_metafiles_as_png = False
options.show_hidden_slides = True
options.best_images_compression_ratio = True
input_ppt.save(pdfpath, slides.export.SaveFormat.PDF, options)

input_pdf = PdfReader(pdfpath)
output = PdfWriter()
page = 436
output.add_page(input_pdf.pages[page])
with open(f"{filename}[{page+1}].pdf", "wb") as OUTPUT_FOLDER:
    output.write(OUTPUT_FOLDER)

@LicenciasTQ,
Thank you for describing the issue.

We are sorry that you had to encounter this problem. To investigate the case and help you, please share the following files and information:

  • input presentation file and output PDF file (you can share a link to the files saved in Google Drive, Dropbox, etc.)
  • OS version on which the conversion was performed
  • Python version you used
  • PyPDF2 version you used
  • Aspose.Slides version you used