I am using aspose slides python library, i have bunch of custom fonts loaded in the fonts folder and when i try to load and convert a sample pptx to pdf, i get the pdf generated with no text! When i comment the line where i load the custom font and then run the conversion I get pdf with text on it. What am i doing wrong ? Below is the code:
def ppt_handler(binary_data):
start_time = time.time()
try:
# Generate unique temporary file names using UUID
input_file_temp_location = f"/tmp/{uuid.uuid4()}.pptx"
output_file_temp_location = f"/tmp/{uuid.uuid4()}.pdf"
# Write the binary data to a temporary location
with open(input_file_temp_location, 'wb') as temp_file:
temp_file.write(binary_data)
# Initialize Aspose.Slides
license = slides.License()
license_path = os.path.join(os.path.dirname(__file__), 'license/aspose.lic')
license.set_license(license_path)
# Set up font settings
curr_folder = os.path.dirname(__file__).split('/')
curr_folder.pop()
curr_folder.pop()
fonts_folder = os.path.join('/'.join(curr_folder), 'fonts/')
slides.FontsLoader.clear_cache()
#If i comment the below line it works
slides.FontsLoader.load_external_fonts([fonts_folder])
loadOptions = slides.LoadOptions()
loadOptions.default_regular_font = "Arial"
loadOptions.default_asian_font = "Arial"
# Load the PPT/PPTX document
presentation = slides.Presentation(input_file_temp_location, loadOptions)
# Save the presentation as PDF
presentation.save(output_file_temp_location, slides.export.SaveFormat.PDF)
# Read the PDF file and encode it in base64
with open(output_file_temp_location, 'rb') as pdf_file:
encoded_pdf = base64.b64encode(pdf_file.read()).decode('utf-8')
execution_time = time.time() - start_time
slides.FontsLoader.clear_cache()
LogUtil.info(f"Lambda execution time: {execution_time} seconds")
# Clean up temporary files
os.remove(input_file_temp_location)
os.remove(output_file_temp_location)