using TECIT.TFORMer; internal static class Program { private static int Main(string[] args) { string format = args.Length == 0 ? "csv" : args[0].ToLowerInvariant(); if (args.Length > 1 || (format != "csv" && format != "xml")) { Console.Error.WriteLine("Usage: dotnet run -- [csv|xml]"); return 1; } string layoutPath = Path.Combine(AppContext.BaseDirectory, "ProductLabel.tff"); string inputPath = Path.Combine(AppContext.BaseDirectory, $"Data.{format}"); if (!File.Exists(layoutPath) || !File.Exists(inputPath)) { Console.Error.WriteLine($"Required files: {layoutPath} and {inputPath}"); return 1; } try { string outputDirectory = Path.Combine( Path.GetTempPath(), "TFORMerDataImport", Guid.NewGuid().ToString("N")); Directory.CreateDirectory(outputDirectory); string outputPath = Path.Combine(outputDirectory, "ProductLabels.pdf"); using Job job = new(); job.RepositoryName = layoutPath; if (format == "csv") { // CSV-START string csvPath = Path.Combine(AppContext.BaseDirectory, "Data.csv"); job.JobData = new JobDataCsv(csvPath, ',', '"'); // CSV-END } else { // XML-START string xmlPath = Path.Combine(AppContext.BaseDirectory, "Data.xml"); job.JobData = new JobDataXml(xmlPath); // XML-END } job.PrinterType = PrinterType.PdfFile; job.OutputName = outputPath; job.Print(); if (!File.Exists(outputPath) || new FileInfo(outputPath).Length == 0) { Console.Error.WriteLine($"TFORMer did not create a non-empty PDF: {outputPath}"); return 1; } Console.WriteLine($"Created PDF: {outputPath}"); return 0; } catch (TFORMerException exception) { Console.Error.WriteLine($"TFORMer error: {exception.Message}"); return 1; } catch (IOException exception) { Console.Error.WriteLine($"File error: {exception.Message}"); return 1; } catch (UnauthorizedAccessException exception) { Console.Error.WriteLine($"Access error: {exception.Message}"); return 1; } } }