AddEmbeddedFonts.cs
C# VB
//// This code is part of Document Solutions for PDF .NET demos.// Copyright (c) MESCIUS inc. All rights reserved.//using System.IO;using GrapeCity.Documents.Pdf;
namespace DsPdfWeb.Demos.Basics{ // This example shows how to convert an existing PDF that does not // have fonts embedded into the PDF with embedded fonts. public class AddEmbeddedFonts { public int CreatePDF(Stream stream) { // Load a PDF that does not have embedded fonts: using var fs = File.OpenRead(Path.Combine("Resources", "PDFs", "CompleteJavaScriptBook-nofonts.pdf")); var docSrc = new GcPdfDocument(); docSrc.Load(fs);
// Create a new document and draw each page of the original PDF into it: var doc = new GcPdfDocument(); // Not really needed as EmbedSubset is the default for new GcPdfDocument: // doc.FontEmbedMode = FontEmbedMode.EmbedSubset; foreach (var p in docSrc.Pages) { var pNew = doc.NewPage(); pNew.Size = p.Size; pNew.Graphics.DrawPdfPage(p, p.Bounds); }
// Done: doc.Save(stream); return doc.Pages.Count; } }}