Text kerning, rotated text, and drawing circles, arcs and ellipses.
Example_05.pdf — the PDF this example creates.
/*
* Example_05.cs
*
* Copyright (c) 2026 PDFjet Software
* Licensed under the MIT License. See LICENSE file in the project root.
*/
using System;
using System.IO;
using System.Diagnostics;
using PDFjet.NET;
/**
* Example_05.cs
*
* Draws text at every angle around a point, and the words "WAVE AWAY" with and
* without kerning, in the core font Helvetica-Bold, which is not embedded.
*
* A core font is one of the fourteen fonts every PDF viewer has, so the
* document carries no font program: it is small, it is written fast, and the
* kerning pairs and the widths of the font are built into the library, which
* is what SetKernPairs shows. The disadvantages: the viewer draws the text with
* its own version of the font, so the look differs a little between viewers;
* only the WinAnsi characters can be drawn, so no Cyrillic, Greek or CJK text;
* and a document with a font that is not embedded cannot claim PDF/A or PDF/UA
* compliance. For those, use an embedded font like IBM Plex Sans, as the
* other examples do.
*/
public class Example_05 {
public Example_05() {
PDF pdf = new PDF(new BufferedStream(
new FileStream("Example_05.pdf", FileMode.Create)));
Font f1 = new Font(pdf, CoreFont.HELVETICA_BOLD);
f1.SetItalic(true);
Page page = new Page(pdf, Letter.PORTRAIT);
TextLine text = new TextLine(f1);
text.SetLocation(300f, 300f);
for (int i = 0; i < 360; i += 15) {
text.SetTextRotation(-i);
text.SetUnderline(true);
// text.SetStrikeout(true);
text.SetText(" Hello, World -- " + i + " degrees.");
text.DrawOn(page);
}
text = new TextLine(f1, "WAVE AWAY");
text.SetLocation(70f, 50f);
text.DrawOn(page);
f1.SetKernPairs(true);
text = new TextLine(f1, "WAVE AWAY");
text.SetLocation(70f, 70f);
text.DrawOn(page);
f1.SetKernPairs(false);
text = new TextLine(f1, "WAVE AWAY");
text.SetLocation(70f, 90f);
text.DrawOn(page);
f1.SetSize(8f);
text = new TextLine(f1, "-- font.setKernPairs(false);");
text.SetLocation(150f, 50f);
text.DrawOn(page);
text.SetLocation(150f, 90f);
text.DrawOn(page);
text = new TextLine(f1, "-- font.setKernPairs(true);");
text.SetLocation(150f, 70f);
text.DrawOn(page);
Point point = new Point(300f, 300f);
point.SetShape(Shape.CIRCLE);
point.SetFillColor(Color.blue);
point.SetRadius(37f);
point.DrawOn(page);
point.SetRadius(25f);
point.SetFillColor(Color.white);
point.DrawOn(page);
float[] arcPoints = (new Arc())
.SetLocation(300f, 600f)
.SetRadiusX(75f)
.SetRadiusY(75f)
.SetStartAngle(0f)
.SetSweep(270f)
// .SetSweep(-270f)
// .ScaleBy(2f)
.SetStrokeWidth(5f)
.SetStrokeColor(Color.blue)
.DrawOn(page);
(new Ellipse())
.SetLocation(300f, 720f)
.SetRadiusX(100f)
.SetRadiusY(50f)
.SetFillColor(Color.azure)
.SetStrokeWidth(1.5f)
.SetStrokeColor(Color.blue)
.ScaleBy(0.5f)
.SetRotation(45f)
.DrawOn(page);
pdf.Complete();
}
public static void Main(String[] args) {
Stopwatch sw = Stopwatch.StartNew();
long time0 = sw.ElapsedMilliseconds;
new Example_05();
long time1 = sw.ElapsedMilliseconds;
Console.WriteLine($"Example_05 => {time1 - time0,4} ms");
}
} // End of Example_05.cs
©2026 PDFjet Software.