EasyBulletList.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 System.Drawing;using GrapeCity.Documents.Pdf;using GrapeCity.Documents.Text;using GrapeCity.Documents.Drawing;using GCTEXT = GrapeCity.Documents.Text;using GCDRAW = GrapeCity.Documents.Drawing;
namespace DsPdfWeb.Demos.Basics{ // Shows how to easily render a simple bullet list using a single TextLayout. public class EasyBulletList { public int CreatePDF(Stream stream) { const int FontSize = 12; var doc = new GcPdfDocument(); var page = doc.Pages.Add(); var g = page.Graphics; var tl = g.CreateTextLayout();
var img = GCDRAW.Image.FromFile(Path.Combine("Resources", "ImagesBis", "2020-website-gcdocs-headers_tall.png")); var rc = page.Bounds; rc.Height *= 0.65f; g.DrawImage(img, rc, null, ImageAlign.StretchImage);
var ip = new PointF(48, 72);
var font = GCTEXT.Font.FromFile(Path.Combine("Resources", "Fonts", "NotoSans-Regular.ttf")); var tfCap = new TextFormat() { Font = font, FontSize = FontSize * 1.6f, ForeColor = Color.White }; var tf = new TextFormat() { Font = font, FontSize = FontSize, ForeColor = Color.White }; tl.MaxWidth = 72 * 6;
// Header: tl.AppendLine("Feature-Rich C# .NET PDF API Library for Total Document Control", tfCap); tl.AppendLine(tfCap); tl.AppendLine("Document Solutions for PDF (DsPdf, previously GcPdf) allows you to generate documents with speed, memory efficiency with no dependencies.", tf); tl.AppendLine(tf); g.DrawTextLayout(tl, ip);
// Bullet list: ip.Y += tl.ContentHeight; tl.Clear(); const string bullet = "\x2022\x2003"; tl.FirstLineIndent = -g.MeasureString(bullet, tf).Width; tl.ParagraphSpacing += 4;
tl.Append(bullet, tf); tl.AppendLine("Generate, load, edit, and save PDF documents in C# or VB", tf); tl.Append(bullet, tf); tl.AppendLine("Support multiple languages with full text, paragraph formatting, and fonts", tf); tl.Append(bullet, tf); tl.AppendLine("Mark and redact sensitive content from PDFs", tf); tl.Append(bullet, tf); tl.AppendLine("View or embed audio and video content in PDFs", tf); tl.Append(bullet, tf); tl.AppendLine("Multiple options for optimizing PDF documents", tf); tl.Append(bullet, tf); tl.AppendLine("Support hundreds of PDF features", tf); tl.Append(bullet, tf); tl.AppendLine("All features are fully supported on Windows, macOS, and Linux", tf); tl.Append(bullet, tf); tl.AppendLine("Includes a JavaScript PDF Viewer to view and edit PDF documents", tf); g.DrawTextLayout(tl, ip);
doc.Save(stream); return doc.Pages.Count; } }}