// This code is part of Document Solutions for PDF demos.
// Copyright (c) MESCIUS inc. All rights reserved.
using System;
using System.IO;
using System.Linq;
using System.Drawing;
using System.Collections.Generic;
using GrapeCity.Documents.Pdf;
using GrapeCity.Documents.Svg;
using GrapeCity.Documents.Drawing;
using GrapeCity.Documents.Text;

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();

            // 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:
            return doc.Pages.Count;