ParagraphAlign.cs
// 
// このコードは、DioDocs for PDF のサンプルの一部として提供されています。
// © MESCIUS inc. All rights reserved.
// 
using System;
using System.Drawing;
using System.IO;
using GrapeCity.Documents.Pdf;
using GrapeCity.Documents.Text;

namespace DsPdfWeb.Demos.Basics
{
    // このサンプルは、段落の配置オプションを示します
    // (水平 LTR テキストの場合は top/center/justified/bottom)。
    public class ParagraphAlign
    {
        public int CreatePDF(Stream stream)
        {
            var doc = new GcPdfDocument();
            var page = doc.NewPage();
            var g = page.Graphics;
            var tl = g.CreateTextLayout();
            tl.DefaultFormat.FontName = "Yu Gothic";
            tl.DefaultFormat.FontSize = 12;
            var borderColor = Color.FromArgb(217, 217, 217);

            var h = (page.Size.Height - 72) / 5;
            var bounds = new RectangleF(36, 36, page.Size.Width - 72, h);

            tl.MaxWidth = bounds.Width;
            tl.MaxHeight = bounds.Height;

            var para = Environment.NewLine + Common.Util.getString_ja(0, 0, 1, 7, 10);

            // 1: ParagraphAlignment.Near
            tl.ParagraphAlignment = ParagraphAlignment.Near;
            tl.Append("ParagraphAlignment.Near: ");
            tl.Append(para);
            tl.PerformLayout(true);
            g.DrawTextLayout(tl, bounds.Location);
            g.DrawRectangle(bounds, borderColor);

            // 2: ParagraphAlignment.Center
            bounds.Offset(0, h);
            tl.Clear();
            tl.ParagraphAlignment = ParagraphAlignment.Center;
            tl.Append("ParagraphAlignment.Center: ");
            tl.Append(para);
            tl.PerformLayout(true);
            g.DrawTextLayout(tl, bounds.Location);
            g.DrawRectangle(bounds, borderColor);

            // 3: ParagraphAlignment.Justified
            bounds.Offset(0, h);
            tl.Clear();
            tl.ParagraphAlignment = ParagraphAlignment.Justified;
            tl.Append("ParagraphAlignment.Justified: ");
            tl.Append(para);
            tl.PerformLayout(true);
            g.DrawTextLayout(tl, bounds.Location);
            g.DrawRectangle(bounds, borderColor);

            // 4: ParagraphAlignment.Distributed
            bounds.Offset(0, h);
            tl.Clear();
            tl.ParagraphAlignment = ParagraphAlignment.Distributed;
            tl.Append("ParagraphAlignment.Distributed: ");
            tl.Append(para);
            tl.PerformLayout(true);
            g.DrawTextLayout(tl, bounds.Location);
            g.DrawRectangle(bounds, borderColor);

            // 5: ParagraphAlignment.Far
            bounds.Offset(0, h);
            tl.Clear();
            tl.ParagraphAlignment = ParagraphAlignment.Far;
            tl.Append("ParagraphAlignment.Far: ");
            tl.Append(para);
            tl.PerformLayout(true);
            g.DrawTextLayout(tl, bounds.Location);
            g.DrawRectangle(bounds, borderColor);

            // PDF ドキュメントを保存します。
            doc.Save(stream);
            return doc.Pages.Count;
        }
    }
}