Type1FontsDemo.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.Drawing;
  8. using GrapeCity.Documents.Pdf;
  9. using GrapeCity.Documents.Text;
  10.  
  11. namespace DsPdfWeb.Demos
  12. {
  13. // This sample demonstrates that as of version 4.1,
  14. // DsPdf supports rendering PDFs that include text
  15. // that uses Adobe Type 1 Font specification fonts.
  16. // Compare images generated by this sample (e.g. TIFF)
  17. // with images generated by the same code but using
  18. // and older version of DsPdf (v4 or earlier) to see
  19. // the difference.
  20. public class Type1FontsDemo
  21. {
  22. public int CreatePDF(Stream stream)
  23. {
  24. var doc = new GcPdfDocument();
  25. // We load a PDF that uses PDF Type 1 fonts, add some text to it,
  26. // and save it to PDF and images (JPEG and TIFF) as in all other samples.
  27. // The original text in the loaded PDF is rendered using Adobe Type 1 fonts,
  28. // so if using DsPdf v4.0 or earlier, the generated images would contain
  29. // garbled text. Starting with v4.1, Type 1 fonts are rendered correctly.
  30. using var fs = File.OpenRead(Path.Combine("Resources", "PDFs", "Type1FontSample.pdf"));
  31. doc.Load(fs);
  32. // Add note to the (only) page in the doc:
  33. var page = doc.Pages.Last;
  34. Common.Util.AddNote(
  35. "This sample demonstrates rendering Adobe Type 1 fonts when a PDF is saved as image by DsPdf. " +
  36. "This is supported starting with DsPdf v4.1. To see the result, open the generated PDF " +
  37. "saved as image (e.g. TIFF). Using the same code with an earlier version of DsPdf produces " +
  38. "garbled text in the saved image.",
  39. page,
  40. new RectangleF(12, 12, 72 * 5, 0));
  41. // Done:
  42. doc.Save(stream);
  43. return doc.Pages.Count;
  44. }
  45. }
  46. }
  47.