Rochas.PDFGenerator
1.2.0
dotnet add package Rochas.PDFGenerator --version 1.2.0
NuGet\Install-Package Rochas.PDFGenerator -Version 1.2.0
<PackageReference Include="Rochas.PDFGenerator" Version="1.2.0" />
<PackageVersion Include="Rochas.PDFGenerator" Version="1.2.0" />
<PackageReference Include="Rochas.PDFGenerator" />
paket add Rochas.PDFGenerator --version 1.2.0
#r "nuget: Rochas.PDFGenerator, 1.2.0"
#:package Rochas.PDFGenerator@1.2.0
#addin nuget:?package=Rochas.PDFGenerator&version=1.2.0
#tool nuget:?package=Rochas.PDFGenerator&version=1.2.0
Rochas.PDFGenerator
Biblioteca .NET para geração de PDFs a partir de templates, modelos (T) ou DataTables, com suporte completo a cabeçalhos com logotipo, paginação no rodapé, estilos e cores de fontes, marca-d'água, tabelas estilizadas, layout multi-colunas e placeholders altamente customizáveis.
Baseada em QuestPDF e compatível com .NET Standard 2.1+.
📦 Instalação
dotnet add package Rochas.PDFGenerator
🚀 Visão Geral
A classe principal é PDFComposer, oferecendo 7 modos de geração de PDF:
| Modo | Descrição |
|---|---|
| Template + Placeholders | Substituição de chaves {{Nome}} com estilos individuais |
| Model Genérico (T) | Objeto mapeado automaticamente para placeholders |
| DataTable | PDF tabular com cabeçalhos/linhas |
| Multi-Colunas | Dois templates lado a lado com proporções configuráveis |
| Lista Multi-Colunas | N colunas via lista de templates |
| Tabela Estilizada | DataTable com bordas, cores alternadas, header customizado |
| Tabela + Model Header | Header com dados do objeto + tabela de itens |
⚙️ Configuração (PdfConfig)
A classe PdfConfig centraliza todas as configurações:
var config = new PdfConfig
{
MarginLeft = 40,
MarginRight = 40,
MarginTop = 50,
MarginBottom = 50,
FontFamily = PdfFontFamily.Montserrat,
CustomFontBytes = File.ReadAllBytes("fonts/Montserrat-Regular.ttf"),
Header = new PdfHeaderConfig
{
LogoBytes = File.ReadAllBytes("images/logo.png"),
LogoAlign = PdfLogoAlignment.Left,
Title = "Relatório XYZ"
},
WatermarkBytes = File.ReadAllBytes("images/watermark.png"),
WatermarkOpacity = 30,
FooterPagination = true,
// Modo Tabela (opcional)
Table = new PdfTableConfig
{
Style = PdfTableStyle.Bordered,
HeaderColor = "#1E3A5F",
AlternatingRowColor = "#F0F4F8"
},
// Modo Colunas (opcional)
Columns = new PdfColumnConfig
{
Count = 2,
Ratios = new[] { 60f, 40f },
Gap = 10
}
};
Compatibilidade:
PdfPageConfigurationePdfHeaderCompositioncontinuam funcionando como aliases.
📄 Modo 1 — Template + Placeholders
var template = "Cliente: {{Nome}}\nData: {{Data}}";
var placeholders = new Dictionary<PdfBodyPlaceHolder, string>
{
{ new PdfBodyPlaceHolder { Key = "{{Nome}}", Style = new PdfPlaceHolderStyle { Bold = true, FontSizePx = 16 } }, "ACME Ltda" },
{ new PdfBodyPlaceHolder { Key = "{{Data}}", Style = new PdfPlaceHolderStyle { Italic = true } }, DateTime.Now.ToString("dd/MM/yyyy") }
};
byte[] pdf = composer.GeneratePdf(template, placeholders, config);
📦 Modo 2 — Model Genérico (T)
var cliente = new { Nome = "ACME Ltda.", Documento = "00.000.000/0001-00" };
byte[] pdf = composer.GeneratePdf("Cliente: {{Nome}}\nDoc: {{Documento}}", cliente, config);
📊 Modo 3 — DataTable
DataTable table = new DataTable();
table.Columns.Add("Produto");
table.Columns.Add("Quantidade");
table.Rows.Add("Caderno", 10);
byte[] pdf = composer.GeneratePdf(table, config);
📐 Modo 4 — Multi-Colunas (2 colunas)
config.Columns = new PdfColumnConfig { Count = 2, Ratios = new[] { 60f, 40f }, Gap = 10 };
var leftPlaceholders = new Dictionary<PdfBodyPlaceHolder, string>
{
{ new PdfBodyPlaceHolder { Key = "{{Nome}}" }, "ACME Ltda." },
{ new PdfBodyPlaceHolder { Key = "{{Doc}}" }, "00.000.000/0001-00" }
};
var rightPlaceholders = new Dictionary<PdfBodyPlaceHolder, string>
{
{ new PdfBodyPlaceHolder { Key = "{{Data}}" }, "07/08/2026" },
{ new PdfBodyPlaceHolder { Key = "{{Total}}" }, "R$ 1.500,00" }
};
byte[] pdf = composer.GeneratePdf(
"Nome: {{Nome}}\nDoc: {{Doc}}", leftPlaceholders,
"Data: {{Data}}\nTotal: {{Total}}", rightPlaceholders,
config);
📐 Modo 5 — Lista Multi-Colunas (N colunas)
var columns = new List<(string Template, Dictionary<PdfBodyPlaceHolder, string> Placeholders)>
{
("Nome: {{Nome}}\nDoc: {{Doc}}", leftPlaceholders),
("Data: {{Data}}\nPedido: {{Pedido}}", centerPlaceholders),
("Total: {{Total}}\nStatus: {{Status}}", rightPlaceholders)
};
byte[] pdf = composer.GeneratePdf(columns, config);
📋 Modo 6 — Tabela Estilizada
config.Table = new PdfTableConfig
{
Style = PdfTableStyle.Bordered,
HeaderColor = "#1E3A5F",
HeaderTextBold = true,
AlternatingRowColor = "#F0F4F8",
FontSize = 10,
RowPadding = 5
};
DataTable table = new DataTable();
table.Columns.Add("Produto");
table.Columns.Add("Qtd");
table.Columns.Add("Valor");
table.Rows.Add("Notebook", 2, "R$ 12.000,00");
byte[] pdf = composer.GeneratePdf(table, config);
📋 Modo 7 — Tabela + Model Header
var headerModel = new { Cliente = "ACME Ltda.", CNPJ = "00.000.000/0001-00", Data = "07/08/2026" };
var tableConfig = new PdfTableConfig
{
Style = PdfTableStyle.Bordered,
HeaderColor = "#1E3A5F"
};
byte[] pdf = composer.GeneratePdf(table, headerModel, tableConfig, config);
📋 PdfTableConfig — Estilos de Tabela
new PdfTableConfig
{
Style = PdfTableStyle.Bordered, // Bordered | Striped | Minimal | Grid
HeaderColor = "#1E3A5F",
HeaderTextBold = true,
HeaderFontSize = 10,
AlternatingRowColor = "#F0F4F8",
FontSize = 10,
RowPadding = 5,
ShowBorders = true,
BorderColor = "#CCCCCC"
};
📐 PdfColumnConfig — Colunas
new PdfColumnConfig
{
Count = 2, // Número de colunas
Ratios = new[] { 60f, 40f }, // Proporções (null = auto-fit igual)
Gap = 10, // Espaço entre colunas
DividerStyle = PdfColumnDividerStyle.None
};
🧪 Exemplo Completo
var composer = new PDFComposer(
author: "Sistema XYZ",
title: "Relatório de Clientes",
subject: "Clientes Ativos",
creationDate: DateTime.Now
);
var config = new PdfConfig
{
FontFamily = PdfFontFamily.Montserrat,
Header = new PdfHeaderConfig
{
LogoBytes = File.ReadAllBytes("logo.png"),
LogoAlign = PdfLogoAlignment.Left,
Title = "Relatório de Clientes"
},
WatermarkBytes = File.ReadAllBytes("watermark.png"),
WatermarkOpacity = 20,
FooterPagination = true,
Table = new PdfTableConfig
{
Style = PdfTableStyle.Bordered,
HeaderColor = "#1E3A5F"
}
};
byte[] pdf = composer.GeneratePdf(table, config);
File.WriteAllBytes("Clientes.pdf", pdf);
🛠 Integração via ASP.NET Core
return File(pdfBytes, "application/pdf", "relatorio.pdf");
📄 Licença
GPL v2 — livre para uso comercial e pessoal.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
| .NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.1 is compatible. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- QuestPDF (>= 2026.7.2)
- Rochas.ImageGenerator (>= 1.1.2)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.