How to set up a URL path as a font source?

How to set up a URL path as a font source?

using Aspose.Words;
using Aspose.Words.Fonts;

// Set the font sources
FontSettings.DefaultInstance.SetFontsSources(new FontSourceBase[]
{
    new SystemFontSource(), // System fonts
    new FolderFontSource("C:\\MyFonts\\", true) // Custom folder
});

// Load your document
Document doc = new Document("path/to/your/document.docx");

// Save the document as PDF
doc.Save("path/to/output/document.pdf");

@suren

To set up a URL path as a font source in Aspose.Words, you can utilize the FontSettings class to specify custom font sources. However, it’s important to note that Aspose.Words primarily supports local file paths for font sources, such as system fonts or folder paths.

If you want to use a URL as a font source, you would typically need to download the font file to a local directory first and then set that local path as the font source. Here’s how you can do it:

  1. Download the font file from the URL to a local directory.
  2. Set the font source using the local path.

Here’s an example of how to implement this in C#:

using Aspose.Words;
using Aspose.Words.Fonts;
using System.Net;

// Step 1: Download the font file
string fontUrl = "http://example.com/path/to/font.ttf";
string localFontPath = "C:\\MyFonts\\font.ttf";
using (WebClient webClient = new WebClient())
{
    webClient.DownloadFile(fontUrl, localFontPath);
}

// Step 2: Set the font sources
FontSettings.DefaultInstance.SetFontsSources(new FontSourceBase[]
{
    new SystemFontSource(), // System fonts
    new FolderFontSource("C:\\MyFonts\\", true) // Custom folder with downloaded font
});

// Load your document
Document doc = new Document("path/to/your/document.docx");

// Save the document as PDF
doc.Save("path/to/output/document.pdf");

In this example, the font is downloaded from a specified URL and saved to a local directory. Then, the local directory is set as a font source, allowing Aspose.Words to use the downloaded font when processing the document.

If you have any further questions or need additional assistance, feel free to ask!

Is it possible to set a SAS URI directly without creating a WebClient?

@suren Unfortunately, there is no way t use SAS URI directly ad font source. You can load fonts one by one and pass them to Aspose.Words using StreamFontSource or MemoryFontSource.

Thanks for the responding.

1 Like