OpenAC.Net.NFSe.DANFSe.PDFSharp.Web 1.8.2

Prefix Reserved
dotnet add package OpenAC.Net.NFSe.DANFSe.PDFSharp.Web --version 1.8.2
                    
NuGet\Install-Package OpenAC.Net.NFSe.DANFSe.PDFSharp.Web -Version 1.8.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenAC.Net.NFSe.DANFSe.PDFSharp.Web" Version="1.8.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenAC.Net.NFSe.DANFSe.PDFSharp.Web" Version="1.8.2" />
                    
Directory.Packages.props
<PackageReference Include="OpenAC.Net.NFSe.DANFSe.PDFSharp.Web" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OpenAC.Net.NFSe.DANFSe.PDFSharp.Web --version 1.8.2
                    
#r "nuget: OpenAC.Net.NFSe.DANFSe.PDFSharp.Web, 1.8.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OpenAC.Net.NFSe.DANFSe.PDFSharp.Web@1.8.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OpenAC.Net.NFSe.DANFSe.PDFSharp.Web&version=1.8.2
                    
Install as a Cake Addin
#tool nuget:?package=OpenAC.Net.NFSe.DANFSe.PDFSharp.Web&version=1.8.2
                    
Install as a Cake Tool

OpenAC.Net.NFSe.DANFSe.PDFSharp.Web

Gera o DANFSe em memória e devolve o PDF como resposta HTTP em aplicações ASP.NET Core (.NET 8, 9, 10 e 11). O serviço recebe uma nota autorizada ou uma coleção de notas para reunir no mesmo documento.

Instalação

dotnet add package OpenAC.Net.NFSe.DANFSe.PDFSharp.Web

Baixar o DANFSe em uma Minimal API

O exemplo recebe o XML de uma NFS-e autorizada no corpo da requisição. Em um projeto criado com dotnet new web, coloque o código abaixo em Program.cs e ajuste o código IBGE ao município que emitiu o XML.

using System.Xml;
using System.Xml.Linq;
using OpenAC.Net.NFSe;
using OpenAC.Net.NFSe.DANFSe.PDFSharp.Web.Service;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenDANFSeWeb(options =>
{
    options.ForcarDownload = true;
    options.NomeArquivo = nota => $"DANFSe-{nota.IdentificacaoNFSe.Numero}.pdf";
});

var app = builder.Build();
app.MapPost("/danfse", async (HttpRequest request, IOpenDANFSeWeb pdf, CancellationToken ct) =>
{
    XDocument xml;
    try
    {
        xml = await XDocument.LoadAsync(request.Body, LoadOptions.None, ct);
    }
    catch (XmlException)
    {
        return Results.BadRequest("Informe um documento XML válido.");
    }

    using var nfse = new OpenNFSe();
    nfse.Configuracoes.WebServices.CodigoMunicipio = 3529005; // Marília (SP)
    var nota = nfse.NotasServico.Load(xml);
    return await pdf.GerarResultadoAsync(nota, cancellationToken: ct);
});
app.Run();

Inicie a aplicação com dotnet run --urls http://localhost:5080. Com um arquivo nfse.xml do município configurado, faça o download do documento.

curl --fail --header "Content-Type: application/xml" --data-binary @nfse.xml http://localhost:5080/danfse --output danfse.pdf

Conteúdo, layout e impressão por empresa

GerarResultadoAsync cria a resposta HTTP com o tipo application/pdf. Ative ForcarDownload para sugerir o download ao navegador. Para armazenar o PDF ou anexá-lo a uma mensagem, chame GerarAsync e use os bytes de Conteudo no documento retornado. O serviço também aceita um array de notas para gerar um único PDF.

No registro de AddOpenDANFSeWeb, ajuste options.Configuracoes para definir cabeçalho, margens e logotipos. Para personalizar por empresa, implemente INFSeConfigurationProvider<DANFSeWebOptions>, retorne opções novas em cada chamada e registre AddOpenDANFSeWeb<EmpresaDANFSeConfigurationProvider>(). Passe a identidade da empresa em GerarAsync ou GerarResultadoAsync. O token permite cancelar a obtenção da configuração. A renderização pelo PDFsharp é síncrona.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed.  net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.8.2 54 12/2/2026
1.8.1 140 10/28/2026