Aspose - Powerpoint font injection

MD
S
Markdown

Font injection using Aspose cloud

1import asposeslidescloud
2from asposeslidescloud.configuration import Configuration
3from asposeslidescloud.apis.slides_api import SlidesApi
4
5# Configure API credentials
6configuration = Configuration()
7configuration.app_sid = '90e7XXX'  # Replace with your Client ID
8configuration.app_key = 'a16bYYYY'  # Replace with your Client Secret
9api = SlidesApi(configuration)
10
11# Read the input PowerPoint file
12with open("MyPresentation.pptx", 'rb') as f:
13    presentation_data = f.read()
14
15print(f"Presentation data length: {len(presentation_data)} bytes")
16print(f"First 50 bytes: {presentation_data[:50].hex()}")
17
18# Read the font file (e.g., calibri.ttf)
19with open("Montserrat-Regular.ttf", 'rb') as f:
20    font_data = f.read()
21
22print(f"Font data length: {len(font_data)} bytes")
23print(f"First 50 bytes: {font_data[:50].hex()}")
24
25try:
26    # Get the temporary file path from the API
27    temp_file_path = api.set_embedded_font_from_request_online(
28        document=presentation_data,
29        font=font_data,
30        only_used=False
31    )
32
33    # Read the temporary file
34    with open(temp_file_path, 'rb') as temp_file:
35        modified_presentation = temp_file.read()
36
37    # Save to our target file
38    with open('ModifiedPresentation_WithMontserrat.pptx', 'wb') as f:
39        f.write(modified_presentation)
40
41    print("Font embedded successfully. Modified PPTX saved as 'ModifiedPresentation_WithMontserrat.pptx'.")
42
43except asposeslidescloud.rest.ApiException as e:
44    print(f"API Error: {e}")
45except Exception as e:
46    print(f"Error: {e}")

Created on 2/7/2025