Programmatic pdf document creation - majorsilence/Reporting GitHub Wiki

Programmatic pdf document creation requires Majorsilence.Reporting.RdlCreator / Majorsilence.Reporting.RdlCreator.SkiaSharp 5.0.4-alpha or newer.

<PackageReference Include="Majorsilence.Reporting.RdlCreator" />

The internal implementation is a combination of rdl and iTextSharp.LGPLv2.Core.

This is experimental and is subject to change.

Example multi page document.

using Majorsilence.Reporting.RdlCreator;

// One time per app instance
RdlEngineConfig.RdlEngineConfigInit();

var document = new Majorsilence.Reporting.RdlCreator.Document()
{
    Description = "Sample report",
    Author = "John Doe",
    PageHeight = "11in",
    PageWidth = "8.5in",
    //Width = "7.5in",
    TopMargin = ".25in",
    LeftMargin = ".25in",
    RightMargin = ".25in",
    BottomMargin = ".25in"
}
.WithPage((page) =>
{
    page.WithHeight("10in")
    .WithWidth("7.5in")
    .WithText(new Text
    {
        Name = "TheSimplePageText",
        Top = ".1in",
        Left = ".1in",
        Width = "6in",
        Height = ".25in",
        Value = new Value { Text = "Text Area 1" },
        Style = new Style { FontSize = "12pt", FontWeight = "Bold" }
    });
})
.WithPage((page) =>
{
    page.WithHeight("10in")
    .WithWidth("7.5in")
    .WithText(new Text
    {
        Name = "Textbox1",
        Top = ".1in",
        Left = ".1in",
        Width = "6in",
        Height = ".25in",
        Value = new Value { Text = "Text Area 1" },
        Style = new Style { FontSize = "12pt", FontWeight = "Bold" }
    })
    .WithText(new Text
    {
        Name = "TheComplexPageText",
        Top = "1in",
        Left = "1in",
        Width = "6in",
        Height = "4in",
        Value = new Value { Text = "Lorem ipsum." },
        Style = new Style
        {
            FontSize = "12pt",
            BackgroundColor = "gray"
        }
    });
    page.WithPageFooter(new PageFooter
    {
        Height = "14pt",
        ReportItems = new ReportItemsFooter
        {
            Textbox = new Text
            {
                Name = "Footer",
                Top = "1pt",
                Left = "10pt",
                Height = "12pt",
                Width = "3in",
                Value = new Value { Text = $"{i}" },
                Style = new Style { FontSize = "10pt", FontWeight = "Normal" }
            }
        },
        PrintOnFirstPage = "true",
        PrintOnLastPage = "true"
    });

    page.WithPageHeader(
        new PageHeader
        {
            Height = ".5in",
            ReportItems = new ReportItemsHeader
            {
                Textbox = new Text
                {
                    Name = "Header",
                    Top = ".1in",
                    Left = ".1in",
                    Width = "6in",
                    Height = ".25in",
                    Value = new Value { Text = "Test Header" },
                    Style = new Style { FontSize = "15pt", FontWeight = "Bold" }
                }
            },
            PrintOnFirstPage = "true",
            PrintOnLastPage = "true"
        });
});

using var fileStream = new FileStream("PLACEHOLDER.pdf", FileMode.Create, FileAccess.Write);
await document.Create(fileStream);