-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
41 lines (38 loc) · 1.23 KB
/
Copy pathProgram.cs
File metadata and controls
41 lines (38 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
using System.Xml.Linq;
using iText.Kernel.Pdf;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;
using iText.Kernel.Font;
using iText.IO.Font.Constants;
using System.Dynamic;
using System.Text.Json;
namespace KSeF_PDF_Generator
{
class Program
{
static void Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Usage: KsefInvoiceConverter <xml-file> [output-pdf]");
return;
}
var xmlFile = args[0];
var outputFile = args.Length > 1 ? args[1] : Path.ChangeExtension(xmlFile, ".pdf");
var nrKSeF = args.Length > 2 ? args[2] : null;
var ksefHash = args.Length > 3 ? args[3] : null;
try
{
var xmlStr = File.ReadAllText(xmlFile);
var pdfBytes = KsefInvoiceGenerator.GenerateInvoiceFromString(xmlStr, nrKSeF, ksefHash: ksefHash);
File.WriteAllBytes(outputFile, pdfBytes);
Console.WriteLine($"PDF generated: {outputFile} ({pdfBytes.Length} bytes)");
}
catch (Exception ex)
{
Console.WriteLine($"Error: {ex}");
}
}
}
}