We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to get all fonts available in system

Hi Team,

string dataDir = RunExamples.GetDataDir_AsposePdf_WorkingDocuments();
Document doc = new Document(dataDir + "input.pdf");
Aspose.Pdf.Text.Font[] fonts = doc.FontUtilities.GetAllFonts();
foreach (Aspose.Pdf.Text.Font font in fonts)
{
    Console.WriteLine(font.FontName);
}

Using above code  I am getting the fonts available in uploaded document. But my requirement is to manipulate the font of text with all the system fonts available in my system.

Please help me with code to get the collection of fonts available in my system to fulfill the requirements.

Thanks and Regards,
Harish G.

@HarishGali
To do this, you should use the general API, something like this

    var fonts = new InstalledFontCollection();
    Console.WriteLine("installed fonts:");
    foreach (FontFamily family in fonts.Families)
    {
        Console.WriteLine(family.Name);
    }

Thank you for quick response, I need to know how to set the font from font collection to each and every text fragment in first page of document. give me reference to set any font from the font collection to text fragments.

Thanks and Regards,
Harish G.

@HarishGali
Here is a code snippet that will make it clear to you how to do it. Examples of additional text snippet customization options are provided in the commented lines.

string inFile = Path.Combine(myDir, "input.pdf");
string outFile = Path.Combine(myDir, "output.pdf");

// Create font and mark it to be embedded.
Aspose.Pdf.Text.Font font = FontRepository.FindFont("Courier New");
font.IsEmbedded = true;

// Open document.
var doc = new Document(inFile);

// Create PdfContentEditor object to edit text.
var editor = new PdfContentEditor();
editor.BindPdf(doc);

// Create textState object.
var textState = new TextState();
textState.Font = font;
//textState.FontSize = 17;
//textState.FontStyle = Aspose.Pdf.Text.FontStyles.Bold | Aspose.Pdf.Text.FontStyles.Italic;
textState.ForegroundColor = Color.FromRgb(System.Drawing.Color.Red);
//textState.BackgroundColor = Color.FromRgb(System.Drawing.Color.Green);

// Change text with specified font.
editor.ReplaceText("Test", 1, "Test", textState);

// Save document.
doc.Save(outFile);

I’m sorry for the late reply.