AddEmbeddedFonts.cs
  1. //
  2. // This code is part of Document Solutions for PDF demos.
  3. // Copyright (c) MESCIUS inc. All rights reserved.
  4. //
  5. using System;
  6. using System.IO;
  7. using System.Linq;
  8. using System.Drawing;
  9. using System.Collections.Generic;
  10. using GrapeCity.Documents.Pdf;
  11. using GrapeCity.Documents.Svg;
  12. using GrapeCity.Documents.Drawing;
  13. using GrapeCity.Documents.Text;
  14.  
  15. namespace DsPdfWeb.Demos.Basics
  16. {
  17. // This example shows how to convert an existing PDF that does not
  18. // have fonts embedded into the PDF with embedded fonts.
  19. public class AddEmbeddedFonts
  20. {
  21. public int CreatePDF(Stream stream)
  22. {
  23. // Load a PDF that does not have embedded fonts:
  24. using var fs = File.OpenRead(Path.Combine("Resources", "PDFs", "CompleteJavaScriptBook-nofonts.pdf"));
  25. var docSrc = new GcPdfDocument();
  26. docSrc.Load(fs);
  27.  
  28. // Create a new document and draw each page of the original PDF into it:
  29. var doc = new GcPdfDocument();
  30. // Not really needed as EmbedSubset is the default for new GcPdfDocument:
  31. // doc.FontEmbedMode = FontEmbedMode.EmbedSubset;
  32. foreach (var p in docSrc.Pages)
  33. {
  34. var pNew = doc.NewPage();
  35. pNew.Size = p.Size;
  36. pNew.Graphics.DrawPdfPage(p, p.Bounds);
  37. }
  38.  
  39. // Done:
  40. doc.Save(stream);
  41. return doc.Pages.Count;
  42. }
  43. }
  44. }
  45.