''
'' This code is part of Document Solutions for Word demos.
'' Copyright (c) MESCIUS inc. All rights reserved.
''
Imports System.IO
Imports GrapeCity.Documents.Word
'' This sample shows how to list fonts embedded in a DOCX.
Public Class ListEmbedFonts
Function CreateDocx() As GcWordDocument
Dim doc = New GcWordDocument()
doc.Load(Path.Combine("Resources", "WordDocs", "EmbedFonts.docx"))
Dim embeddedFont = doc.Fonts.FirstOrDefault(Function(fi_) fi_.Embedded.Count > 1)?.Embedded(0)
doc.Body.Paragraphs.Add("Embedded fonts found in this document:", doc.Styles(BuiltInStyleId.Heading1))
Dim myListTemplate = doc.ListTemplates.Add(BuiltInListTemplateId.BulletDefault, "myListTemplate")
For Each fi In doc.Fonts
For Each ef In fi.Embedded
Dim p = doc.Body.Paragraphs.Add(doc.Styles(BuiltInStyleId.ListParagraph))
p.ListFormat.Template = myListTemplate
Dim run = p.GetRange().Runs.Add($"Found embedded font of type {ef.Type} in font ""{fi.Name}"".")
run.Font.Name = fi.Name
If ef.Type = EmbeddedFontType.Bold Then
run.Font.Bold = True
ElseIf ef.Type = EmbeddedFontType.Italic Then
run.Font.Italic = True
ElseIf ef.Type = EmbeddedFontType.BoldItalic Then
run.Font.Bold = True
run.Font.Italic = True
End If
Next
Next
Return doc
End Function
End Class