items) {
+ StringBuilder itemsHtml = new StringBuilder();
+
+ if (items != null) {
+ for (InvoiceItem item : items) {
+ itemsHtml.append("")
+ .append("| ")
+ .append(escapeHtml(safeString(item.getQuantity())))
+ .append(" | ")
+ .append("")
+ .append(escapeHtml(safeString(item.getDescription())))
+ .append(" | ")
+ .append("")
+ .append(escapeHtml(safeString(item.getUnitPrice())))
+ .append(" | ")
+ .append("")
+ .append(escapeHtml(safeString(item.getTotalPrice())))
+ .append(" | ")
+ .append("
");
+ }
+ }
+
+ // Add empty rows to fill the table (up to 12 rows total as in original)
+ int emptyRowsNeeded = Math.max(0, 12 - (items != null ? items.size() : 0));
+ StringBuilder emptyRowsHtml = new StringBuilder();
+ for (int i = 0; i < emptyRowsNeeded; i++) {
+ emptyRowsHtml.append("")
+ .append("| | ")
+ .append(" | ")
+ .append(" | ")
+ .append(" | ")
+ .append("
");
+ }
+
+ // Remove template placeholders
+ String result = template.replace("{{#invoiceItems}}", "")
+ .replace("{{/invoiceItems}}", "")
+ .replace("{{#emptyRows}}", "")
+ .replace("{{/emptyRows}}", "");
+
+ // Replace the placeholder with actual items
+ String itemsPlaceholder = "{{invoiceItems}}";
+ if (result.contains(itemsPlaceholder)) {
+ result = result.replace(itemsPlaceholder, itemsHtml.toString() + emptyRowsHtml.toString());
+ }
+
+ return result;
+ }
+
+ private String safeString(String value) {
+ return value != null ? value : "";
+ }
+
+ private String escapeHtml(String value) {
+ if (value == null) return "";
+ return value.replace("&", "&")
+ .replace("<", "<")
+ .replace(">", ">")
+ .replace("\"", """)
+ .replace("'", "'");
+ }
+
+ public InvoiceData createSampleInvoiceData() {
+ return pdfBoxService.createSampleInvoiceData();
+ }
+}
\ No newline at end of file
diff --git a/src/main/resources/templates/invoice-template.html b/src/main/resources/templates/invoice-template.html
new file mode 100644
index 0000000..c6b7549
--- /dev/null
+++ b/src/main/resources/templates/invoice-template.html
@@ -0,0 +1,259 @@
+
+
+
+
+ Rechnung {{invoiceNumber}}
+
+
+
+
+
+
+
{{senderLine}}
+
{{recipientName}}
+
{{recipientDepartment}}
+
{{recipientStreet}}
+
{{recipientCity}}
+
+
+
+
{{companyStreet}}
+
{{companyCity}}
+
+
Tel.: {{companyPhone}}
+
{{companyWebsite}}
+
+
+
+
+
+ Fax
+ eMail
+
+ {{companyFax}}
+ {{companyEmail}}
+
+
+
+ Datum
+ {{invoiceDate}}
+
+
+ Rechnung {{invoiceNumber}}
+
+ {{invoiceText}}
+
+
+
+
+
+
+
+
+ {{invoiceItems}}
+
+ | |
+ |
+
+ {{netAmount}} |
+
+
+ | |
+ |
+ + {{vatRate}}% MwSt. |
+ {{vatAmount}} |
+
+
+ | |
+ |
+
+ {{totalAmount}} |
+
+
+
+
+ {{paymentTerms}}
+
+
+
+
+
\ No newline at end of file