EasyBulletList.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. using GrapeCity.Documents.Drawing;
  11. using GCTEXT = GrapeCity.Documents.Text;
  12. using GCDRAW = GrapeCity.Documents.Drawing;
  13.  
  14. namespace DsPdfWeb.Demos.Basics
  15. {
  16. // Shows how to easily render a simple bullet list using a single TextLayout.
  17. public class EasyBulletList
  18. {
  19. public int CreatePDF(Stream stream)
  20. {
  21. const int FontSize = 12;
  22. var doc = new GcPdfDocument();
  23. var page = doc.Pages.Add();
  24. var g = page.Graphics;
  25. var tl = g.CreateTextLayout();
  26.  
  27. var img = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "2020-website-gcdocs-headers_tall.png"));
  28. var rc = page.Bounds;
  29. rc.Height *= 0.65f;
  30. g.DrawImage(img, rc, null, ImageAlign.StretchImage);
  31.  
  32. var ip = new PointF(48, 72);
  33.  
  34. var font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "OpenSans-Regular.ttf"));
  35. var tfCap = new TextFormat() { Font = font, FontSize = FontSize * 1.6f, ForeColor = Color.White };
  36. var tf = new TextFormat() { Font = font, FontSize = FontSize, ForeColor = Color.White };
  37. tl.MaxWidth = 72 * 6;
  38.  
  39. // Header:
  40. tl.AppendLine("Feature-Rich C# .NET PDF API Library for Total Document Control", tfCap);
  41. tl.AppendLine(tfCap);
  42. tl.AppendLine("Document Solutions for PDF (DsPdf, previously GcPdf) allows you to generate documents with speed, memory efficiency with no dependencies.", tf);
  43. tl.AppendLine(tf);
  44. g.DrawTextLayout(tl, ip);
  45.  
  46. // Bullet list:
  47. ip.Y += tl.ContentHeight;
  48. tl.Clear();
  49. const string bullet = "\x2022\x2003";
  50. tl.FirstLineIndent = -g.MeasureString(bullet, tf).Width;
  51. tl.ParagraphSpacing += 4;
  52.  
  53. tl.Append(bullet, tf);
  54. tl.AppendLine("Generate, load, edit, and save PDF documents in C# or VB", tf);
  55. tl.Append(bullet, tf);
  56. tl.AppendLine("Support multiple languages with full text, paragraph formatting, and fonts", tf);
  57. tl.Append(bullet, tf);
  58. tl.AppendLine("Mark and redact sensitive content from PDFs", tf);
  59. tl.Append(bullet, tf);
  60. tl.AppendLine("View or embed audio and video content in PDFs", tf);
  61. tl.Append(bullet, tf);
  62. tl.AppendLine("Multiple options for optimizing PDF documents", tf);
  63. tl.Append(bullet, tf);
  64. tl.AppendLine("Support hundreds of PDF features", tf);
  65. tl.Append(bullet, tf);
  66. tl.AppendLine("All features are fully supported on Windows, macOS, and Linux", tf);
  67. tl.Append(bullet, tf);
  68. tl.AppendLine("Includes a JavaScript PDF Viewer to view and edit PDF documents", tf);
  69. g.DrawTextLayout(tl, ip);
  70.  
  71. doc.Save(stream);
  72. return doc.Pages.Count;
  73. }
  74. }
  75. }
  76.