Aspose - Powerpoint font injection

MD
S
Markdown

Font injection using Aspose cloud

import asposeslidescloud from asposeslidescloud.configuration import Configuration from asposeslidescloud.apis.slides_api import SlidesApi

Configure API credentials

configuration = Configuration() configuration.app_sid = '90e7XXX' # Replace with your Client ID configuration.app_key = 'a16bYYYY' # Replace with your Client Secret api = SlidesApi(configuration)

Read the input PowerPoint file

with open("MyPresentation.pptx", 'rb') as f: presentation_data = f.read()

print(f"Presentation data length: {len(presentation_data)} bytes") print(f"First 50 bytes: {presentation_data[:50].hex()}")

Read the font file (e.g., calibri.ttf)

with open("Montserrat-Regular.ttf", 'rb') as f: font_data = f.read()

print(f"Font data length: {len(font_data)} bytes") print(f"First 50 bytes: {font_data[:50].hex()}")

try: # Get the temporary file path from the API temp_file_path = api.set_embedded_font_from_request_online( document=presentation_data, font=font_data, only_used=False )

# Read the temporary file
with open(temp_file_path, 'rb') as temp_file:
    modified_presentation = temp_file.read()

# Save to our target file
with open('ModifiedPresentation_WithMontserrat.pptx', 'wb') as f:
    f.write(modified_presentation)

print("Font embedded successfully. Modified PPTX saved as 'ModifiedPresentation_WithMontserrat.pptx'.")

except asposeslidescloud.rest.ApiException as e: print(f"API Error: {e}") except Exception as e: print(f"Error: {e}")

Created on 2/7/2025