/* * Example_20.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.Diagnostics; using PDFjet.NET; /** * Example_20.cs */ public class Example_20 { public Example_20() { PDF pdf = new PDF(new BufferedStream( new FileStream("Example_20.pdf", FileMode.Create))); pdf.SetCompliance(Compliance.PDF_UA_1); pdf.SetTitle("Electric Vehicle Population"); Font f1 = new Font(pdf, IBMPlexSans.SemiBold); f1.SetSize(7f); Font f2 = new Font(pdf, IBMPlexSans.Regular); f2.SetSize(7f); Font f3 = new Font(pdf, IBMPlexSans.BoldItalic); f3.SetSize(7f); Image image = new Image(pdf, "images/TeslaX.png"); image.SetAltDescription( "A white Tesla Model X with a black glass roof, seen from the front left."); image.ScaleBy(1f/3f); // The image is 120 DPI, so 0.6 of its pixels Barcode barcode = new Barcode(Barcode.CODE_128, "Hello, World!"); barcode.SetModuleLength(0.75f); // Comment out the line below if you don't want to print the text underneath the barcode. barcode.SetFont(f1); Table table = new Table(f1, f2, "data/Electric_Vehicle_Population_10_Pages.csv"); table.SetVisibleColumns(1, 2, 3, 4, 5, 6, 7, 9); table.GetCellAt(4, 0).SetImage(image); table.GetCellAt(5, 0).SetColSpan(8); table.GetCellAt(5, 0).SetBarcode(barcode); table.GetCellAt(20, 0).SetColSpan(6); table.GetCellAt(20, 6).SetColSpan(2); table.AutoAdjustColumnWidths(); table.SetColumnWidth(0, image.GetWidth() + 4f); table.SetColumnWidth(3, table.GetColumnWidth(3) + 10f); table.SetColumnWidth(5, table.GetColumnWidth(5) + 10f); table.RightAlignNumbers(); table.SetLocation(30f, 30f); // table.SetFirstPageTopMargin(150f); table.SetBottomMargin(15f); table.SetTextColorInRow(12, Color.blue); table.SetTextColorInRow(13, Color.firebrick); table.SetFontInRow(14, f3); // A heading on the first page only, which the table starts under: the // first page is made here, and the table goes on to new pages. Page first = new Page(pdf, Letter.PORTRAIT, false); new TextLine(f1, "Electric Vehicle Population") .SetStructureType(StructElem.H1) .SetFontSize(14f) .SetLocation(30f, 44f) .DrawOn(first); table.SetFirstPageTopMargin(56f); List pages = new List(); pages.Add(first); table.DrawOn(pdf, first, pages, Letter.PORTRAIT); for (int i = 0; i < pages.Count; i++) { Page page = pages[i]; page.AddFooter(new TextLine(f1, "Page " + (i + 1) + " of " + pages.Count)); pdf.AddPage(page); } pdf.Complete(); } public static void Main(String[] args) { Stopwatch sw = Stopwatch.StartNew(); long time0 = sw.ElapsedMilliseconds; new Example_20(); long time1 = sw.ElapsedMilliseconds; sw.Stop(); Console.WriteLine($"Example_20 => {time1 - time0,4} ms"); } } // End of Example_20.cs