Code Monkey home page Code Monkey logo

arraytopdf's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.