'''' This code is part of Document Solutions for PDF .NET demos.'' Copyright (c) MESCIUS inc. All rights reserved.''ImportsSystem.IOImportsSystem.DrawingImportsSystem.Collections.GenericImportsSystem.LinqImportsGrapeCity.Documents.PdfImportsGrapeCity.Documents.Text '' This sample lists all fonts found in a loaded PDF,'' prints some info for each font, And indicates whether a Font object'' can be created from the font in the PDF.PublicClassListFontsFunctionCreatePDF(ByVal stream AsStream) AsIntegerDim sourcePDF = "CompleteJavaScriptBook.pdf" Dim doc = NewGcPdfDocument()Dim page = doc.NewPage() Dim rc = Util.AddNote("This sample loads an arbitrary PDF into a temporary GcPdfDocument, " +"and lists all fonts found in that document, with some of their properties. " +"It also tries to create a Font object from each of those PDF fonts, " +"and reports whether this operation succeeded.", page) '' Text layout to render the text:Dim tab = 24Dim tl = page.Graphics.CreateTextLayout() tl.DefaultFormat.Font = StandardFonts.Times tl.DefaultFormat.FontSize = 12 tl.MaxWidth = doc.PageSize.Width tl.MaxHeight = doc.PageSize.Height tl.MarginAll = rc.Left tl.MarginTop = rc.Bottom + 36 tl.TabStops = NewList(OfTabStop)() From {NewTabStop(tab)} tl.FirstLineIndent = -tab tl.MarginRight = 144 '' Text split options for widow/orphan control:Dim tso = NewTextSplitOptions(tl) With { .KeepParagraphLinesTogether = True, .MinLinesInFirstParagraph = 2, .MinLinesInLastParagraph = 2, .RestMarginTop = rc.Left } '' Open an arbitrary PDF, load it into a temp document and get all fonts:Using fs = NewFileStream(Path.Combine("Resources", "PDFs", sourcePDF), FileMode.Open, FileAccess.Read)Dim doc1 = NewGcPdfDocument() doc1.Load(fs)Dim fonts = doc1.GetFonts() tl.AppendLine($"Total of {fonts.Count} fonts found in {sourcePDF}:") tl.AppendLine()Dim i AsInteger = 0ForEach fnt In fontsDim nativeFont = fnt.CreateNativeFont() tl.Append($"{i}:{vbTab}BaseFont: {fnt.BaseFont}; IsEmbedded: {fnt.IsEmbedded}.") tl.AppendParagraphBreak()If nativeFont IsNotNothingThen tl.AppendLine($"{vbTab}CreateNativeFont succeeded, family: {nativeFont.FontFamilyName}; bold: {nativeFont.FontBold}; italic: {nativeFont.FontItalic}.")Else tl.AppendLine($"{vbTab}CreateNativeFont failed")EndIf tl.AppendLine() i += 1Next tl.PerformLayout(True)While (True)'' 'rest' will accept the text that did not fit:Dim rest AsTextLayout = NothingDim splitResult = tl.Split(tso, rest) doc.Pages.Last.Graphics.DrawTextLayout(tl, PointF.Empty)If splitResult <> SplitResult.SplitThenExitWhileEndIf tl = rest doc.NewPage()EndWhileEndUsing'' Done: doc.Save(stream)Return doc.Pages.CountEndFunctionEndClass