/* * Example_15.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.Collections.Generic; using System.Text.RegularExpressions; using System.Diagnostics; using PDFjet.NET; /** * Example_15.cs */ public class Example_15 { public Example_15() { PDF pdf = new PDF(new BufferedStream( new FileStream("Example_15.pdf", FileMode.Create))); pdf.SetCompliance(Compliance.PDF_UA_1); pdf.SetTitle("Text flowing through columns"); Font f1 = new Font(pdf, IBMPlexSans.Regular); f1.SetSize(14f); // Use Regex.Split to match Java's split("\\n\\n") regex behavior List paragraphs = new List( Regex.Split(Content.OfTextFile("data/dostoevsky.txt"), "\\n\\n")); float x = 50f; float y = 50f; float w = 230f; float h = 500f; float gap = 20f; Page page = null; TextFrame textFrame = new TextFrame(f1, paragraphs); bool first = true; while (textFrame.HasMoreText()) { page = new Page(pdf, Letter.LANDSCAPE); if (first) { // The heading, on the first page only, which its columns start under new TextLine(f1, "The Idiot, by Fyodor Dostoevsky") .SetStructureType(StructElem.H1) .SetFontSize(20f) .SetLocation(50f, 50f) .DrawOn(page); y = 80f; first = false; } textFrame.SetLocation(x, y); textFrame.SetWidth(w); textFrame.SetHeight(h); textFrame.DrawOn(page); if (textFrame.HasMoreText()) { x += w + gap; textFrame.SetLocation(x, y); textFrame.SetWidth(w); textFrame.SetHeight(h); textFrame.DrawOn(page); } if (textFrame.HasMoreText()) { x += w + gap; textFrame.SetLocation(x, y); textFrame.SetWidth(w); textFrame.SetHeight(h); textFrame.DrawOn(page); } x = 50f; y = 50f; } pdf.Complete(); } public static void Main(String[] args) { Stopwatch sw = Stopwatch.StartNew(); long time0 = sw.ElapsedMilliseconds; new Example_15(); long time1 = sw.ElapsedMilliseconds; sw.Stop(); Console.WriteLine($"Example_15 => {time1 - time0,4} ms"); } } // End of Example_15.cs