FontEmbeddingStatus.vb
C# VB
'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''Imports System.IOImports System.DrawingImports System.LinqImports System.Collections.ImmutableImports System.Collections.GenericImports GrapeCity.Documents.PdfImports GrapeCity.Documents.Pdf.TextImports GrapeCity.Documents.Text
Public Class FontEmbeddingStatus Public Function CreatePDF(ByVal stream As Stream) As Integer Const pdfName As String = "C1Olap-QuickStart.pdf" Dim fs = File.OpenRead(Path.Combine("Resources", "PDFs", pdfName)) Dim doc = New GcPdfDocument() doc.Load(fs)
Dim page = doc.Pages.Insert(0) Dim g = page.Graphics Dim tl = g.CreateTextLayout() tl.AppendLine($"Fonts used in {pdfName}, and their embedding status:" & vbLf) ' List fonts and their embedding states: Dim ff = doc.GetFonts().ToImmutableArray().Select(Function(f_) GetFontInfo(f_)).DistinctBy(Function(fi_) fi_.Item2).OrderBy(Function(fi_) fi_.Item2) For Each fi In ff tl.AppendLine($"- ""{fi.Item2}"": {EmbedModeToString(fi.Item1)}") Next
tl.MarginAll = g.Resolution g.DrawTextLayout(tl, PointF.Empty)
doc.Save(stream) Return doc.Pages.Count End Function
Private Function GetFontInfo(font As GrapeCity.Documents.Pdf.Text.Font) As (FontEmbedMode, String) If font.IsEmbedded Then Dim p = font.BaseFont.IndexOf("+"c) If p > 0 Then Return (FontEmbedMode.EmbedSubset, font.BaseFont.Substring(p + 1)) Else Return (FontEmbedMode.EmbedFullFont, font.BaseFont) End If End If Return (FontEmbedMode.NotEmbed, font.BaseFont) End Function
Private Function EmbedModeToString(fem As FontEmbedMode) As String If fem = FontEmbedMode.EmbedFullFont Then Return "Embedded font" ElseIf fem = FontEmbedMode.EmbedSubset Then Return "Embedded subset" Else Return "Not embedded" End If End FunctionEnd Class