Danfe Generator

ASP.NET Core web application that generates a Danfe (NF-e PDF) from an uploaded XML file. The system automatically extracts the invoice access key and produces the corresponding printable document.


Overview

Danfe Generator is a web tool designed to simplify the process of generating a Danfe document from an NF-e XML file.

The application reads the uploaded XML, extracts the invoice access key from the <infNFe> node and generates the corresponding PDF using DinkToPdf and wkhtmltopdf.


Features

  • Upload NF-e XML files
  • Automatic extraction of the invoice access key
  • DANFE PDF generation
  • PDF named based on the invoice key
  • Service-based architecture (SRP)
  • Clean and simple UI
  • Cross-platform support (Windows & Linux)

Application Flow

  1. User uploads an XML file
  2. The system reads the document
  3. The access key is extracted from the infNFe element
  4. The PDF generator service creates the DANFE
  5. The file is returned with the invoice key as the filename

Technologies

  • .NET 8
  • ASP.NET Core MVC
  • Dependency Injection
  • Bootstrap
  • DinkToPdf
  • wkhtmltopdf

Example


string xmlContent = File.ReadAllText("nota.xml");

string chave = NFeKeyExtractor.Extract(xmlContent);

byte[] pdf = danfeService.Generate(xmlContent);

Error Handling

  • Invalid XML → controlled exception
  • Unsupported model → handled error
  • Unexpected errors → structured logging