Skip to content

Create PDF from Array (List, DataTable, ...)

License

Notifications You must be signed in to change notification settings

mustaddon/ArrayToPdf

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ArrayToPdf NuGet version

Create PDF from Array (List, DataTable, ...)

Example 1: Create with default settings

using ArrayToPdf;

var items = Enumerable.Range(1, 100).Select(x => new
{
    Prop1 = $"Text #{x}",
    Prop2 = x * 1000,
    Prop3 = DateTime.Now.AddDays(-x),
});

var pdf = items.ToPdf();

Result: example1.pdf

Example 2: Rename title and columns

var pdf = items.ToPdf(schema => schema
    .Title("Example name")
    .ColumnName(m => m.Name.Replace("Prop", "Column #")));

Result: example2.pdf

Example 3: Sort columns

var pdf = items.ToPdf(schema => schema
    .ColumnSort(m => m.Name, desc: true));

Result: example3.pdf

Example 4: Custom column's mapping

var pdf = items.ToPdf(schema => schema
    .PageOrientation(PdfOrientations.Portrait)
    .PageMarginLeft(15)
    .AddColumn("MyColumnName #1", x => x.Prop1, 30)
    .AddColumn("MyColumnName #2", x => $"test:{x.Prop2}")
    .AddColumn("MyColumnName #3", x => x.Prop3));

Result: example4.pdf

Example 5: Filter columns

var pdf = items.ToPdf(schema => schema
    .ColumnFilter(m => m.Name != "Prop2"));

Result: example5.pdf

Example 6: Create from DataTable

var table = new DataTable("Example Table");

table.Columns.Add("Column #1", typeof(string));
table.Columns.Add("Column #2", typeof(int));
table.Columns.Add("Column #3", typeof(DateTime));

for (var x = 1; x <= 100; x++)
    table.Rows.Add($"Text #{x}", x * 1000, DateTime.Now.AddDays(-x));

var pdf = table.ToPdf();

Result: example6.pdf

Example.ConsoleApp

Releases

No releases published

Packages

No packages published