DPrint 1.0.0

dotnet add package DPrint --version 1.0.0
                    
NuGet\Install-Package DPrint -Version 1.0.0
                    
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="DPrint" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DPrint" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DPrint" />
                    
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 DPrint --version 1.0.0
                    
#r "nuget: DPrint, 1.0.0"
                    
#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 DPrint@1.0.0
                    
#: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=DPrint&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=DPrint&version=1.0.0
                    
Install as a Cake Tool

DPrint

Biblioteca .NET 8 para conversão de HTML e arquivos Excel (XLS/XLSX) para PDF sem dependências externas instaláveis.

Características

  • ✅ Conversão de HTML para PDF
  • ✅ Conversão de Excel (XLS/XLSX) para PDF
  • ✅ Suporte a tabelas HTML
  • ✅ Suporte a múltiplas páginas
  • ✅ Sem dependências instaláveis (não requer Chromium ou outros componentes)
  • ✅ Funciona em qualquer ambiente (VM, Azure App Service, AWS, Linux, Windows)
  • ✅ Gratuito e sem limites de uso
  • ✅ Totalmente gerenciado (managed code)
  • ✅ Compatível com .NET 8
  • ✅ 100% de cobertura de testes

Instalação

Via .NET CLI

dotnet add package DPrint

Via NuGet Package Manager (Visual Studio)

Install-Package DPrint

Via PackageReference

Adicione no arquivo .csproj:

<ItemGroup>
  <PackageReference Include="DPrint" Version="1.0.0" />
</ItemGroup>

Depois execute:

dotnet restore

Uso Rápido

Conversão de HTML para PDF

using DPrint;

var service = new DPrintService();

// Converter string HTML para PDF (retorna bytes)
string html = "<html><body><h1>Olá Mundo</h1></body></html>";
byte[] pdfBytes = service.HtmlToPdf(html);

// Salvar diretamente em arquivo
service.HtmlToPdf(html, "output.pdf");

// Converter arquivo HTML para PDF
service.HtmlFileToPdf("input.html", "output.pdf");

Conversão de Excel para PDF

using DPrint;

var service = new DPrintService();

// Converter arquivo Excel para PDF (retorna bytes)
byte[] pdfBytes = service.ExcelToPdf("planilha.xlsx");

// Salvar diretamente em arquivo
service.ExcelToPdf("planilha.xlsx", "output.pdf");

// Converter stream de Excel para PDF
using var stream = File.OpenRead("planilha.xls");
byte[] pdfBytes = service.ExcelStreamToPdf(stream, isXls: true);

Exemplo com HTML e Tabelas

var html = @"
<html>
    <body>
        <h1>Relatório de Vendas</h1>
        <table border='1'>
            <tr>
                <th>Produto</th>
                <th>Quantidade</th>
                <th>Valor</th>
            </tr>
            <tr>
                <td>Produto A</td>
                <td>10</td>
                <td>R$ 100,00</td>
            </tr>
        </table>
    </body>
</html>";

byte[] pdfBytes = service.HtmlToPdf(html);
File.WriteAllBytes("relatorio.pdf", pdfBytes);

Exemplo em API Web (ASP.NET Core)

[ApiController]
[Route("api/[controller]")]
public class RelatorioController : ControllerBase
{
    private readonly DPrintService _dPrintService;

    public RelatorioController(DPrintService dPrintService)
    {
        _dPrintService = dPrintService;
    }

    [HttpPost("gerar-pdf")]
    public IActionResult GerarPdf([FromBody] string html)
    {
        byte[] pdfBytes = _dPrintService.HtmlToPdf(html);
        return File(pdfBytes, "application/pdf", "relatorio.pdf");
    }
}

Injeção de Dependência

// No Program.cs ou Startup.cs
builder.Services.AddSingleton<DPrintService>();

// No construtor do seu controller/serviço
public class MeuController : ControllerBase
{
    private readonly DPrintService _dPrintService;

    public MeuController(DPrintService dPrintService)
    {
        _dPrintService = dPrintService;
    }
}

Usando as Interfaces Diretamente

Se preferir usar as interfaces diretamente:

using DPrint;

// HTML para PDF
IHtmlToPdfConverter htmlConverter = new HtmlToPdfConverter();
byte[] pdfBytes = htmlConverter.ConvertToPdf("<html>...</html>");

// Excel para PDF
IExcelToPdfConverter excelConverter = new ExcelToPdfConverter();
byte[] pdfBytes = excelConverter.ConvertToPdf("planilha.xlsx");

Requisitos

  • .NET 8.0 ou superior

Dependências

A biblioteca utiliza as seguintes dependências NuGet (todas gerenciadas, sem instalação externa):

  • EPPlus (7.5.2) - Para leitura de arquivos XLSX
  • NPOI (2.7.1) - Para leitura de arquivos XLS (formato antigo)
  • PdfSharpCore (1.3.65) - Para geração de PDF (compatível com .NET 8)

Todas as dependências são totalmente gerenciadas e não requerem instalação de componentes externos.

Funcionalidades Suportadas

HTML para PDF

  • ✅ Texto formatado (parágrafos, títulos H1, H2)
  • ✅ Tabelas HTML com bordas e formatação
  • ✅ Múltiplas páginas automáticas
  • ✅ Quebra de linha automática
  • ✅ HTML básico e limpo

Excel para PDF

  • ✅ Arquivos XLSX (formato moderno)
  • ✅ Arquivos XLS (formato antigo)
  • ✅ Múltiplas abas/planilhas
  • ✅ Conversão via arquivo ou stream
  • ✅ Preservação de estrutura de dados

Limitações

  • HTML complexo com CSS avançado pode não ser totalmente suportado
  • Imagens embutidas no HTML podem não ser renderizadas
  • Apenas fontes padrão do PDF são suportadas (Helvetica, Times-Roman, Courier)

Documentação Completa

Para documentação detalhada, exemplos avançados, tratamento de erros e boas práticas, consulte o MANUAL.md.

Testes

A biblioteca possui 28 testes unitários com 100% de cobertura:

cd DPrint.Tests
dotnet test

Licença

MIT

Contribuições

Contribuições são bem-vindas! Por favor, abra uma issue ou pull request no repositório do projeto.


Versão: 1.0.0
Última atualização: Dezembro 2025

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 was computed.  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 was computed.  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. 
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.0.0 238 12/4/2025