//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//usingSystem.IO;usingSystem.Drawing;usingGrapeCity.Documents.Pdf;usingGrapeCity.Documents.Text; namespaceDsPdfWeb.Demos.Basics{// 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.publicclassListFonts {publicintCreatePDF(Stream stream) {conststringsourcePDF = "CompleteJavaScriptBook.pdf"; var doc = newGcPdfDocument();var page = doc.NewPage();var rc = Common.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:var tab = 24;var 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 = [ new (tab) ]; tl.FirstLineIndent = -tab; tl.MarginRight = 144; // Text split options for widow/orphan control:var to = newTextSplitOptions(tl) {KeepParagraphLinesTogether = true,MinLinesInFirstParagraph = 2,MinLinesInLastParagraph = 2,RestMarginTop = rc.Left, }; // Open an arbitrary PDF, load it into a temp document and get all fonts:usingvar fs = File.OpenRead(Path.Combine("Resources", "PDFs", sourcePDF));var doc1 = newGcPdfDocument(); doc1.Load(fs); var fonts = doc1.GetFonts(); tl.AppendLine($"Total of {fonts.Count} fonts found in {sourcePDF}:"); tl.AppendLine();int i = 0;foreach (var font in fonts) {var nativeFont = font.CreateNativeFont(); tl.Append($"{i}:\tBaseFont: {font.BaseFont}; IsEmbedded: {font.IsEmbedded}."); tl.AppendParagraphBreak();if (nativeFont != null) tl.AppendLine($"\tCreateNativeFont succeeded, family: {nativeFont.FontFamilyName}; bold: {nativeFont.FontBold}; italic: {nativeFont.FontItalic}.");else tl.AppendLine("\tCreateNativeFont failed"); tl.AppendLine(); ++i; } tl.PerformLayout(true);while (true) {// 'rest' will accept the text that did not fit:var splitResult = tl.Split(to, outTextLayout rest); doc.Pages.Last.Graphics.DrawTextLayout(tl, PointF.Empty);if (splitResult != SplitResult.Split)break; tl = rest; doc.NewPage(); }// Done: doc.Save(stream);return doc.Pages.Count; } }}