Learning Objectives
In this tutorial, you’ll learn how to:
- Embed fonts in a presentation stored in cloud storage
- Understand and use the onlyUsed parameter to optimize file size
- Implement font embedding in various programming languages
- Verify that fonts have been properly embedded
Prerequisites
Before starting this tutorial, you should have:
- An Aspose Cloud account with an active subscription
- Your Client ID and Client Secret
- A PowerPoint presentation uploaded to your Aspose Cloud Storage
- Basic understanding of REST API concepts
- Familiarity with font usage in PowerPoint
Why Embedding Fonts Matters
Font embedding ensures that your presentation appears exactly as designed, regardless of whether the recipient has the fonts installed on their system. Key benefits include:
- Consistent appearance across different computers and devices
- Preserves design integrity when sharing presentations
- Ensures proper rendering when converting to other formats like PDF
- Essential for branding consistency when using custom corporate fonts
Step 1: Embedding Fonts in a Presentation in Storage
The API allows you to embed specific fonts that are used in a presentation. Let’s learn how to do this for a presentation that’s already in your cloud storage.
API Details
API | Type | Description | Resource |
---|---|---|---|
/slides/{name}/fonts/embedded/{fontName} | POST | Embeds specified font and returns presentation fonts info. | SetEmbeddedFont |
Understanding Parameters
- name: The name of your presentation file in storage
- fontName: The name of the font to embed
- onlyUsed: A boolean parameter that determines whether to embed only the characters used in the presentation (true) or the entire font (false)
Using onlyUsed=true
can significantly reduce your file size while maintaining all necessary characters.
Try It Yourself
Using cURL
First, authenticate to get your access token:
curl -v "https://api.aspose.cloud/connect/token" \
-X POST \
-d "grant_type=client_credentials&client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET" \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Accept: application/json"
Now, embed a font in your presentation:
curl -X POST "https://api.aspose.cloud/v3.0/slides/MyPresentation.pptx/fonts/embedded/Calibri" \
-H "Authorization: Bearer YOUR_ACCESS_TOKEN"
The response will include information about all fonts in the presentation, including your newly embedded font.
Step 2: Implementing in Different Programming Languages
Let’s see how to implement font embedding in various programming languages:
C# Example
// Tutorial Code Example - Embedding Fonts in C#
using Aspose.Slides.Cloud.Sdk;
using Aspose.Slides.Cloud.Sdk.Api;
using Aspose.Slides.Cloud.Sdk.Model;
using System;
namespace AsposeSlidesFontEmbedding
{
class Program
{
static void Main(string[] args)
{
// Create API instance with your credentials
SlidesApi api = new SlidesApi("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
// Name of the presentation in storage
string presentationName = "MyPresentation.pptx";
// Name of the font to embed
string fontName = "Calibri";
// Whether to embed only used characters (true) or the entire font (false)
bool onlyUsed = false;
try
{
// Embed the font in the presentation
FontsData response = api.SetEmbeddedFont(presentationName, fontName, onlyUsed);
// Display success message
Console.WriteLine($"Font '{fontName}' has been successfully embedded in the presentation.");
// Verify by checking the embedded status in the response
foreach (var font in response.List)
{
if (font.FontName.Equals(fontName, StringComparison.OrdinalIgnoreCase) &&
font.IsEmbedded.HasValue && font.IsEmbedded.Value)
{
Console.WriteLine($"Verified: '{fontName}' is now embedded in the presentation.");
break;
}
}
}
catch (Exception ex)
{
Console.WriteLine($"Error embedding font: {ex.Message}");
}
}
}
}
Python Example
# Tutorial Code Example - Embedding Fonts in Python
import asposeslidescloud
from asposeslidescloud.configuration import Configuration
from asposeslidescloud.apis.slides_api import SlidesApi
# Configure the API client
configuration = Configuration()
configuration.app_sid = 'YOUR_CLIENT_ID'
configuration.app_key = 'YOUR_CLIENT_SECRET'
api = SlidesApi(configuration)
# Name of the presentation in storage
presentation_name = "MyPresentation.pptx"
# Name of the font to embed
font_name = "Calibri"
# Whether to embed only used characters (True) or the entire font (False)
only_used = False
try:
# Embed the font in the presentation
response = api.set_embedded_font(presentation_name, font_name, only_used)
# Display success message
print(f"Font '{font_name}' has been successfully embedded in the presentation.")
# Verify by checking the embedded status in the response
for font in response.list:
if font.font_name.lower() == font_name.lower() and font.is_embedded:
print(f"Verified: '{font_name}' is now embedded in the presentation.")
break
except Exception as ex:
print(f"Error embedding font: {str(ex)}")
Java Example
// Tutorial Code Example - Embedding Fonts in Java
import com.aspose.slides.cloud.sdk.api.SlidesApi;
import com.aspose.slides.cloud.sdk.model.FontsData;
import com.aspose.slides.cloud.sdk.model.FontData;
public class EmbedFontExample {
public static void main(String[] args) {
try {
// Create API instance with your credentials
SlidesApi api = new SlidesApi("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
// Name of the presentation in storage
String presentationName = "MyPresentation.pptx";
// Name of the font to embed
String fontName = "Calibri";
// Whether to embed only used characters (true) or the entire font (false)
boolean onlyUsed = false;
// Embed the font in the presentation
FontsData response = api.setEmbeddedFont(presentationName, fontName, onlyUsed, null, null, null, null);
// Display success message
System.out.println("Font '" + fontName + "' has been successfully embedded in the presentation.");
// Verify by checking the embedded status in the response
for (FontData font : response.getList()) {
if (font.getFontName().equalsIgnoreCase(fontName) &&
font.getIsEmbedded() != null && font.getIsEmbedded()) {
System.out.println("Verified: '" + fontName + "' is now embedded in the presentation.");
break;
}
}
} catch (Exception ex) {
System.out.println("Error embedding font: " + ex.getMessage());
}
}
}
Step 3: Understanding the Embedded Fonts Response
After embedding a font, the API returns a FontsData
object that contains information about all fonts in the presentation. For each font, you’ll see:
- FontName: The name of the font
- IsEmbedded: A boolean indicating whether the font is embedded
- IsCustom: A boolean indicating whether it’s a custom font
This response helps you verify that the font was successfully embedded and provides a complete picture of font usage in your presentation.
Step 4: Working with Presentations in Request Body
Sometimes you need to embed fonts in a presentation that isn’t stored in the cloud. Aspose.Slides Cloud API also provides an endpoint for this scenario:
API Details
API | Type | Description | Resource |
---|---|---|---|
/slides/fonts/embedded/{fontName} | POST | Embeds specified font and returns presentation. | SetEmbeddedFontOnline |
C# Example for Online Mode
// Tutorial Code Example - Embedding Fonts Online in C#
using Aspose.Slides.Cloud.Sdk;
using Aspose.Slides.Cloud.Sdk.Api;
using System;
using System.IO;
namespace AsposeSlidesOnlineFontEmbedding
{
class Program
{
static void Main(string[] args)
{
// Create API instance with your credentials
SlidesApi api = new SlidesApi("YOUR_CLIENT_ID", "YOUR_CLIENT_SECRET");
// Local path to the presentation file
string filePath = "MyPresentation.pptx";
// Name of the font to embed
string fontName = "Calibri";
// Whether to embed only used characters (true) or the entire font (false)
bool onlyUsed = false;
try
{
// Open the presentation file
using (Stream file = File.OpenRead(filePath))
{
// Embed the font and get the updated presentation
using (Stream updatedPresentation = api.SetEmbeddedFontOnline(file, fontName, onlyUsed))
{
// Save the updated presentation
using (FileStream outputStream = File.Create("UpdatedPresentation.pptx"))
{
updatedPresentation.CopyTo(outputStream);
}
}
}
Console.WriteLine($"Font '{fontName}' has been successfully embedded and the presentation has been saved.");
}
catch (Exception ex)
{
Console.WriteLine($"Error embedding font: {ex.Message}");
}
}
}
}
Font Embedding Optimization Tips
Use onlyUsed=true for smaller files: This embeds only the characters used in the presentation, which can significantly reduce file size.
Prioritize non-standard fonts: Common fonts like Arial or Times New Roman usually don’t need to be embedded since they’re available on most systems.
Check font license restrictions: Some fonts have licensing restrictions that may prohibit embedding.
Verify embedding was successful: Always check that the font was properly embedded by checking the IsEmbedded property in the response.
Common Issues and Troubleshooting
Font Not Found
If you receive a “Font not found” error:
- Verify that the font name is spelled correctly (font names are case-sensitive)
- Check that the font is installed on the Aspose.Slides Cloud server
- Consider uploading the font using the SetEmbeddedFontFromRequest method
File Size Concerns
If you’re worried about file size:
- Use
onlyUsed=true
to embed only the characters used in the presentation - Limit embedding to only non-standard fonts
- Consider using CompressEmbeddedFonts to optimize embedded fonts
What You’ve Learned
In this tutorial, you’ve learned:
- How to embed fonts in a presentation stored in cloud storage
- How to optimize font embedding by using the onlyUsed parameter
- How to implement font embedding in different programming languages
- How to verify that fonts have been properly embedded
- How to handle presentations that aren’t stored in the cloud
Further Practice
To reinforce your learning:
- Create a script that checks a presentation for non-standard fonts and embeds them automatically
- Experiment with the onlyUsed parameter to see the impact on file size
- Build a tool that analyzes font usage across multiple presentations and batch-embeds fonts as needed
Next Steps
Now that you know how to embed fonts from the system, learn how to embed custom font files directly from a request.