作成日: 2023/10/17 最終更新日: 2023/10/17
文書種別
使用方法
詳細
PDFに余白を設定する直接的な機能はありませんが、GraphicsのTransformプロパティを使用すると、描画位置の基点を移動できます。
var doc = new GrapeCity.Documents.Pdf.GcPdfDocument();
var page = doc.NewPage();
var g = page.Graphics;
var tf = new GrapeCity.Documents.Text.TextFormat()
{
FontName = "MS Gothic",
FontSize = 10,
};
g.DrawString("ページ左上端", tf, PointF.Empty);
g.Transform = Matrix3x2.CreateTranslation(72, 72);
g.DrawString("基点を1インチ移動", tf, PointF.Empty);
g.DrawString("基点から1インチ下", tf, new PointF(0, 72));
doc.Save("sample.pdf");
また、TextLayoutを使用すると、指定した幅・高さから余白を除いた領域にテキストを描画できます。
var tl = g.CreateTextLayout();
tl.DefaultFormat.FontName = "MS Gothic";
tl.DefaultFormat.FontSize = 30;
tl.MaxWidth = page.Bounds.Width;
tl.MaxHeight = page.Bounds.Height;
tl.MarginAll = 72;
tl.Append("長いテキスト");
for (int i = 0; i < 50; i++) tl.Append("1234567890");
tl.PerformLayout(true);
g.DrawTextLayout(tl, PointF.Empty);