// 完毕:
using System;
using System.IO;
using System.Drawing;
using GrapeCity.Documents.Pdf;
using GrapeCity.Documents.Text;
using GrapeCity.Documents.Drawing;
namespace DsPdfWeb.Demos.Basics
{
// 此示例演示了 WordWrap 和 CharWrap 之间的区别
// 文本换行模式。
public class WordCharWrap
{
public int CreatePDF(Stream stream)
{
var str =
"Lose nothing in your documents! Document Solutions for PDF includes text and paragraph formatting, " +
"special characters, multiple languages, RTL support, vertical and rotated text on all supported platforms.";
var doc = new GcPdfDocument();
var page = doc.NewPage();
var g = page.Graphics;
var tl = g.CreateTextLayout();
tl.Append(str);
tl.DefaultFormat.Font = StandardFonts.Times;
tl.DefaultFormat.FontSize = 12;
tl.MaxWidth = 72 * 3;
tl.WrapMode = WrapMode.WordWrap;
tl.PerformLayout(true);
var dy = tl.Lines[0].Height + 72 / 16;
var rc = new RectangleF(72, 72 + dy, tl.MaxWidth.Value, 72 * 1.4F);
g.DrawString("WrapMode.WordWrap:", tl.DefaultFormat, new PointF(rc.Left, rc.Top - dy));
g.DrawTextLayout(tl, rc.Location);
g.DrawRectangle(rc, Color.CornflowerBlue);
rc.Offset(0, 72 * 2);
tl.WrapMode = WrapMode.CharWrap;
tl.PerformLayout(false);
g.DrawString("WrapMode.CharWrap:", tl.DefaultFormat, new PointF(rc.Left, rc.Top - dy));
g.DrawTextLayout(tl, rc.Location);
g.DrawRectangle(rc, Color.CornflowerBlue);
// 完毕:
doc.Save(stream);
return doc.Pages.Count;
}
}
}