/* * Example_38.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.Text; using System.Diagnostics; using System.Collections.Generic; using PDFjet.NET; /** * Example_38.cs * This example draws a PDF417 barcode that holds a whole source file, with an * explanation and a caption. */ public class Example_38 { public Example_38() { PDF pdf = new PDF(new BufferedStream( new FileStream("Example_38.pdf", FileMode.Create))); pdf.SetCompliance(Compliance.PDF_UA_1); pdf.SetTitle("PDF417 barcode example"); Font f1 = new Font(pdf, IBMPlexSans.Regular); Font f2 = new Font(pdf, IBMPlexSans.SemiBold); Page page = new Page(pdf, Letter.PORTRAIT); TextLine text = new TextLine(f2, "PDF417 Barcode"); text.SetStructureType(StructElem.H1); text.SetFontSize(22f); text.SetLocation(70f, 80f); text.DrawOn(page); TextBlock textBlock = new TextBlock(f1, "PDF417 is a stacked two-dimensional barcode, used on boarding passes, " + "identity cards and shipping labels. It holds text and binary data, " + "and its error correction lets a scanner read it even when part of " + "it is damaged."); textBlock.SetFontSize(12f); textBlock.SetLineSpacing(1.5f); textBlock.SetLocation(70f, 95f); textBlock.SetWidth(470f); float[] xy = textBlock.DrawOn(page); // A barcode that holds a whole source file. List lines = Content.LinesOfTextFile("data/pdf417-sample.java"); StringBuilder buf = new StringBuilder(); foreach (String line in lines) { buf.Append(line); buf.Append("\r\n"); // CR and LF both required! } PDF417 barcode = new PDF417(buf.ToString()); barcode.SetModuleLength(1f); barcode.SetLocation(70f, xy[1] + 30f); xy = barcode.DrawOn(page); text = new TextLine(f1, "The source code of data/pdf417-sample.java, " + lines.Count + " lines"); text.SetFontSize(10f); text.SetTextColor(Color.dimgray); text.SetLocation(70f, xy[1] + 20f); text.DrawOn(page); pdf.Complete(); } public static void Main(String[] args) { Stopwatch sw = Stopwatch.StartNew(); long time0 = sw.ElapsedMilliseconds; new Example_38(); long time1 = sw.ElapsedMilliseconds; sw.Stop(); Console.WriteLine($"Example_38 => {time1 - time0,4} ms"); } }