The Templates directory contains invoice templates, styling, and fonts for generating customized PDF invoices. Each template supports different business requirements and output formats.
Templates/
├── Fonts/ # Font files for all templates
│ ├── Inter/ # Inter font family
│ ├── OpenSans/ # Open Sans font family
│ ├── Roboto/ # Roboto font family
│ └── Lato/ # Lato font family
├── TemplateA/ # Standard business template
│ ├── Header.cshtml # Header section
│ ├── Body.cshtml # Main content
│ ├── Footer.cshtml # Footer section
│ ├── PO_PB_Body.cshtml # Purchase Order/Proforma body
│ ├── PO_PB_Header.cshtml # Purchase Order/Proforma header
│ ├── Receipt_Payment_Body.cshtml # Receipt/Payment body
│ └── Styles/ # CSS styling files
├── Tally/ # Accounting software format
│ ├── Header.cshtml # Header section
│ ├── Body.cshtml # Main content
│ ├── Footer.cshtml # Footer section
│ └── Styles/ # CSS styling files
└── Thermal/ # Receipt printer format
├── Body.cshtml # Compact body layout
└── Styles/ # Minimal styling
Purpose: Professional invoice template for standard business use
Components:
Header.cshtml(@/Users/divyanshu/walkover/GiddhTemplate/Templates/TemplateA/Header.cshtml) - Company branding and invoice detailsBody.cshtml- Line items, calculations, and tax breakdownFooter.cshtml- Terms, conditions, and signaturesPO_PB_Body.cshtml- Purchase Order/Proforma specific layoutPO_PB_Header.cshtml- Purchase Order/Proforma headerReceipt_Payment_Body.cshtml- Receipt and payment voucher layout
Header Features:
@model InvoiceData.Root;
@using InvoiceData;
<header id="header">
<table>
<tbody>
@* Copy type image for Invoice Copy variants *@
@if(Model?.TypeOfCopy != null)
{
<tr>
<td class="p-0 text-center">
<img src="@Model.TypeOfCopy" height="40px" width="auto" />
</td>
</tr>
}Dynamic Elements:
- Company logo with configurable size
- Conditional field display based on settings
- QR code integration for payments
- Tax number and GST composition display
- Multi-language support
Purpose: Compatible with Tally accounting software requirements
Components:
Header.cshtml- Simplified header layoutBody.cshtml- Accounting-focused line itemsFooter.cshtml- Compliance and totalsBackground.css- Specialized background styling
Key Features:
- Tally-compatible field mapping
- Enhanced tax bifurcation display
- Accounting period compliance
- Background watermarks support
Purpose: Optimized for thermal receipt printers
Components:
Body.cshtml- Compact single-column layout- Minimal styling for printer compatibility
Characteristics:
- Single-column layout
- Monospace font optimization
- Minimal graphics
- High contrast text
- Compact spacing
CSS Custom Properties (@/Users/divyanshu/walkover/GiddhTemplate/Templates/TemplateA/Styles/Styles.css:1-50)
Font Variables:
@property --font-family {
syntax: "<string>";
inherits: true;
initial-value: "Inter"; /* 'Roboto' | 'Open Sans' | 'Lato' | 'Inter' */
}
@property --font-size-default {
syntax: "<length>";
inherits: true;
initial-value: 14px;
}
@property --font-size-medium {
syntax: "<length>";
inherits: true;
initial-value: 12px;
}
@property --font-size-small {
syntax: "<length>";
inherits: true;
initial-value: 10px;
}Color Variables:
@property --color-primary {
syntax: "<color>";
inherits: true;
initial-value: #181b50;
}
@property --color-secondary {
syntax: "<color>";
inherits: true;
initial-value: #6c757d;
}Font Weight Variables:
@property --font-weight-200 {
syntax: "<integer>";
inherits: true;
initial-value: 200;
}
@property --font-weight-400 {
syntax: "<integer>";
inherits: true;
initial-value: 400;
}
@property --font-weight-500 {
syntax: "<integer>";
inherits: true;
initial-value: 500;
}
@property --font-weight-700 {
syntax: "<integer>";
inherits: true;
initial-value: 700;
}- CSS custom properties
- Global reset styles
- Base typography
- Color scheme definitions
- Logo positioning and sizing
- Company information layout
- Invoice metadata styling
- QR code positioning
- Table layouts for line items
- Tax calculation displays
- Multi-column layouts
- Responsive adjustments
- Terms and conditions formatting
- Signature areas
- Total calculations
- Contact information
- Watermark positioning
- Background images
- Print-specific styling
- Path:
Templates/Fonts/Inter/ - Weights: 200, 400, 500, 700
- Usage: Modern UI-optimized font
- Best For: Digital invoices, clean layouts
- Path:
Templates/Fonts/Roboto/ - Weights: 200, 400, 500, 700
- Usage: Google Material Design
- Best For: Professional documents
- Path:
Templates/Fonts/OpenSans/ - Weights: 200, 400, 500, 700
- Usage: Humanist sans-serif
- Best For: Readable body text
- Path:
Templates/Fonts/Lato/ - Weights: 200, 400, 500, 700
- Usage: Friendly sans-serif
- Best For: Marketing materials
Dynamic CSS Generation:
public string LoadFontCSS(string fontFamily)
{
if (fontFamily == "Open Sans" && string.IsNullOrEmpty(_openSansFontCSS))
{
string fontPath = Path.Combine(Directory.GetCurrentDirectory(), "Templates", "Fonts", "OpenSans");
_openSansFontCSS = BuildFontCSS("Open Sans", fontPath);
}
// Similar for other fonts...
}Font Face Generation:
@font-face {
font-family: 'Inter';
src: url('data:font/woff2;base64,{base64data}') format('woff2');
font-weight: 400;
font-style: normal;
font-display: swap;
}string templateType = request.TemplateType ?? "TemplateA";
string templatePath = Path.Combine("Templates", templateType);var styles = LoadStyles(templatePath);
// Returns: (Common, Header, Footer, Body, Background)string fontFamily = request.Theme?.Font?.Family ?? "Inter";
string fontCSS = LoadFontCSS(fontFamily);// Header rendering
string headerHtml = await _razorTemplateService.RenderTemplateAsync(
Path.Combine(templatePath, "Header.cshtml"), request);
// Body rendering
string bodyHtml = await _razorTemplateService.RenderTemplateAsync(
Path.Combine(templatePath, "Body.cshtml"), request);
// Footer rendering (if exists)
string footerHtml = await _razorTemplateService.RenderTemplateAsync(
Path.Combine(templatePath, "Footer.cshtml"), request);<style>
{fontCSS}
{styles.Common}
{styles.Header}
{styles.Body}
{styles.Footer}
{styles.Background}
</style>@model InvoiceData.Root;
@using InvoiceData;
@using System.Collections.Generic;@if (Model?.Settings?.ShowLogo?.Display == true &&
!string.IsNullOrEmpty(Model?.Company?.Logo?.Url))
{
<figure class="m-0">
<img src="@Model?.Company?.Logo?.Url"
height="@Model?.Company?.Logo?.Size"
width="auto" />
</figure>
}<td class="p-0 invoice-info vertical-align-bottom"
width="@(Model?.Settings?.ShowQrCode?.Display == true &&
!string.IsNullOrEmpty(Model?.QRCodeBase64String) ? "30%" : "50%")">@if (Model?.Entries != null)
{
@foreach (var entry in Model.Entries)
{
<tr>
<td>@entry.AccountName</td>
<td>@entry.Amount?.AmountForAccount</td>
</tr>
}
}@Model?.Settings?.CompanyTaxNumber?.Label
@(Model?.Company?.TaxNumber ?? "N/A")-
Create Directory Structure:
Templates/NewTemplate/ ├── Header.cshtml ├── Body.cshtml ├── Footer.cshtml (optional) └── Styles/ ├── Styles.css ├── Header.css ├── Body.css └── Footer.css -
Update Template Selection Logic:
// In PdfService.cs case "NewTemplate": templatePath = Path.Combine("Templates", "NewTemplate"); break;
-
Define CSS Variables:
@property --custom-color { syntax: "<color>"; inherits: true; initial-value: #custom; }
-
CSS Customization:
- Modify CSS custom properties for global changes
- Update specific CSS files for targeted changes
- Maintain responsive design principles
-
Razor Template Updates:
- Add new conditional sections
- Modify existing layouts
- Ensure null safety for new fields
-
Font Integration:
- Add new font families to
Templates/Fonts/ - Update font loading logic in
PdfService.cs - Define new font CSS variables
- Add new font families to
- Page Size: A4 (210mm × 297mm)
- Margins: Configurable via Theme.Margin
- Print Background: Enabled for graphics
- Scale: 1.0 for accurate sizing
@media print {
.no-print { display: none; }
.page-break { page-break-before: always; }
body { -webkit-print-color-adjust: exact; }
}- Image Optimization: Base64 encoding for embedded images
- Font Subsetting: Only required glyphs included
- CSS Minification: Reduced file sizes
- Template Caching: Compiled template reuse
-
Template Not Found:
- Verify template directory structure
- Check case sensitivity in file names
- Ensure all required files exist
-
Styling Not Applied:
- Validate CSS syntax
- Check CSS custom property definitions
- Verify style loading order
-
Font Not Loading:
- Confirm font files exist in correct directory
- Validate font file formats (WOFF2 preferred)
- Check font family name consistency
-
Razor Compilation Errors:
- Verify model binding syntax
- Check null safety operators
- Validate using statements
-
HTML Output Inspection:
- Save generated HTML before PDF conversion
- Validate HTML structure and CSS
-
CSS Variable Testing:
- Use browser developer tools
- Test CSS custom property inheritance
-
Template Isolation:
- Test individual template components
- Validate model data structure
Author/Developer: Divyanshu Shrivastava
Last Updated: December 2025