June 09 2025
Install-Package IronPdf
public class Invoice { public string InvoiceNumber { get; set; } public string CompanyName { get; set; } public string ClientName { get; set; } public DateTime Date { get; set; } = DateTime.UtcNow; public List<(string Description, decimal Amount)> Items { get; set; } public decimal Total => Items.Sum(x => x.Amount); }
<!DOCTYPE html> <html> <head> <style> body { font-family: Arial; padding: 30px; } h1 { color: #444; } table { width: 100%; border-collapse: collapse; margin-top: 20px; } th, td { border: 1px solid #ccc; padding: 10px; text-align: left; } .total { text-align: right; font-weight: bold; } </style> </head> <body> <h1>Invoice - </h1> <p><strong>Company:</strong> </p> <p><strong>Client:</strong> </p> <p><strong>Date:</strong> </p> <table> <thead><tr><th>Description</th><th>Amount</th></tr></thead> <tbody> </tbody> </table> <p class="total">Total: $</p> </body> </html>
var invoice = new Invoice { InvoiceNumber = "INV-2024-003", CompanyName = "TheCodeMan", ClientName = "FinTech Innovations Ltd", Items = new() { ("Newsletter Sponsorship", 500), ("LinkedIn Post", 300), ("Twitter Mention", 200) } }; // Load HTML template string htmlTemplate = File.ReadAllText("invoice.html"); // Convert line items to table rows string itemsHtml = string.Join("", invoice.Items.Select(i => $"<tr><td>{i.Description}</td><td>${i.Amount}</td></tr>")); // Replace placeholders with real data string filledHtml = htmlTemplate .Replace("", invoice.InvoiceNumber) .Replace("", invoice.CompanyName) .Replace("", invoice.ClientName) .Replace("", invoice.Date.ToShortDateString()) .Replace("", itemsHtml) .Replace("", invoice.Total.ToString());
// Render to PDF var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf(filledHtml); pdf.SaveAs("Invoice-FinTech.pdf"); Console.WriteLine("Invoice PDF generated!");

var renderer = new ChromePdfRenderer(); var pdf = renderer.RenderHtmlAsPdf(filledHtml); var signature = new PdfSignature("certificate.pfx", "password") { ContactInformation = "stefan@thecodeman.net", SigningReason = "Sponsorship Invoice", SigningLocation = "Nis, Serbia" }; pdf.Sign(signature); pdf.SaveAs("Invoice-FinTech.pdf");
public void MergePdfs() { var pdf1 = PdfDocument.FromFile("doc1.pdf"); var pdf2 = PdfDocument.FromFile("doc2.pdf"); var merged = PdfDocument.Merge(pdf1, pdf2); merged.SaveAs("merged.pdf"); }
1. Design Patterns that Deliver
This isn’t just another design patterns book. Dive into real-world examples and practical solutions to real problems in real applications.Check out it here.
Go-to resource for understanding the core concepts of design patterns without the overwhelming complexity. In this concise and affordable ebook, I've distilled the essence of design patterns into an easy-to-digest format. It is a Beginner level. Check out it here.
Every Monday morning, I share 1 actionable tip on C#, .NET & Arcitecture topic, that you can use right away.
Join 18,000+ subscribers to improve your .NET Knowledge.
Subscribe to the TheCodeMan.net and be among the 18,000+ subscribers gaining practical tips and resources to enhance your .NET expertise.