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

namespace GcPdfWeb.Samples
{
    // このサンプルは、HTMLの文字列をレンダリングする方法を示しています。
    // 
    // GcHtmlをプロジェクトに追加する方法の詳細については、 HelloWorldHtml
    // サンプルコードのトップにあるコメント欄の注意事項をご覧ください。
    public class SideBySide
    {
        public void CreatePDF(Stream stream)
        {
            // シンプルなテーブルをレンダリングするHTML
            const string html =

                "<!DOCTYPE html>" +
                "<html>" +
                "<head>" +
                "<style>" +
                "table, td, th {" +
                "  border: 1px solid black;" +
                "}" +

                "table {" +
                "  border-collapse: collapse;" +
                "  width: 250px;" +
                "}" +

                "th {" +
                "  height: 50px;" +
                "}" +
                "</style>" +
                "</head>" +
                "<body>" +

                "<h2>The width and height Properties</h2>" +
                "<p>Set the width of the table, and the height of the table header row:</p>" +

                "<table style='display: inline-block;'>" +
                "  <tr>" +
                "    <th>Firstname</th>" +
                "    <th>Lastname</th>" +
                "    <th>Savings</th>" +
                "  </tr>" +
                "  <tr>" +
                "    <td>Peter</td>" +
                "    <td>Griffin</td>" +
                "    <td>$100</td>" +
                "  </tr>" +
                "  <tr>" +
                "    <td>Lois</td>" +
                "    <td>Griffin</td>" +
                "    <td>$150</td>" +
                "  </tr>" +
                "</table>" +

                "<table style='float: right;'>" +
                "  <tr>" +
                "    <th>Firstname</th>" +
                "    <th>Lastname</th>" +
                "    <th>Savings</th>" +
                "  </tr>" +
                "  <tr>" +
                "    <td>Peter</td>" +
                "    <td>Griffin</td>" +
                "    <td>$100</td>" +
                "  </tr>" +
                "  <tr>" +
                "    <td>Lois</td>" +
                "    <td>Griffin</td>" +
                "    <td>$150</td>" +
                "  </tr>" +
                "  <tr>" +
                "    <td>Joe</td>" +
                "    <td>Swanson</td>" +
                "    <td>$300</td>" +
                "  </tr>" +
                "  <tr>" +
                "    <td>Cleveland</td>" +
                "    <td>Brown</td>" +
                "    <td>$250</td>" +
                "  </tr>" +
                "</table>" +


                "</body>" +
                "</html>";

            // 新規 PDF ドキュメントを作成します。
            var doc = new GcPdfDocument();
            // ページを追加します。
            var page = doc.NewPage();
            // ページを追加し、そのgraphicsを取得します。
            var g = page.Graphics;

            var nrc =  Common.Util.AddNote(
                "ここでは、サンプルソースにてハードコーディングしたHTMLページにより定義された、" +
                "簡単なテーブルを文字列としてレンダリングしています。" +
                "GcPdfGraphics.DrawHtml()メソッドによって返される、レンダリングされた" +
                "テーブルのサイズに基づいて、テーブルの下にフッターが追加されます。",
                page);

            // HTMLをレンダリングします。
            // 戻り値は、レンダリングされたかどうかを示します。
            // 出力パラメータのsizeは、レンダリングされたコンテンツの実際のサイズを返します。
            var ok = g.DrawHtml(html, nrc.Left, nrc.Bottom + 36,
                new HtmlToPdfFormat(false) { MaxPageWidth = nrc.Width / 72 },
                out SizeF size);

            Common.Util.AddNote(
                "このテキストは、HTMLテーブルの下に追加されます。" +
                "その位置は、GcPdfGraphics.DrawHtml()が返すレンダリングサイズによって決まります。",
                page,
                new RectangleF(nrc.Left, nrc.Bottom + size.Height + 72, nrc.Width, int.MaxValue));

            // PDF を保存します。
            doc.Save(stream);
        }
    }
}