コード例 #1
0
ファイル: TableExamples.cs プロジェクト: lmingle/library
        public void PagingSupport()
        {
            RenderingTest
            .Create()
            .ProducePdf()
            .PageSize(420, 220)
            .ShowResults()
            .Render(container =>
            {
                container
                .Padding(10)
                .MinimalBox()
                .Border(1)
                .Table(table =>
                {
                    table.ColumnsDefinition(columns =>
                    {
                        columns.RelativeColumn();
                        columns.RelativeColumn();
                        columns.RelativeColumn();
                        columns.RelativeColumn();
                    });

                    // by using custom 'Element' method, we can reuse visual configuration
                    table.Cell().Element(Block).Text(Placeholders.Label());
                    table.Cell().Element(Block).Text(Placeholders.Label());
                    table.Cell().Element(Block).Text(Placeholders.Paragraph());
                    table.Cell().Element(Block).Text(Placeholders.Label());
                });
            });
        }
コード例 #2
0
        public void ScaleToFit()
        {
            RenderingTest
            .Create()
            .PageSize(PageSizes.A4)
            .ProduceImages()
            .ShowResults()
            .Render(container =>
            {
                container.Padding(25).Column(column =>
                {
                    var text = Placeholders.Paragraph();

                    foreach (var i in Enumerable.Range(2, 5))
                    {
                        column
                        .Item()
                        .MinimalBox()
                        .Border(1)
                        .Padding(5)
                        .Width(i * 40)
                        .Height(i * 20)
                        .ScaleToFit()
                        .Text(text);
                    }
                });
            });
        }
コード例 #3
0
        public void ParagraphSpacing()
        {
            RenderingTest
            .Create()
            .PageSize(500, 300)
            .ProduceImages()
            .ShowResults()
            .Render(container =>
            {
                container
                .Padding(5)
                .MinimalBox()
                .Border(1)
                .Padding(10)
                .Text(text =>
                {
                    text.ParagraphSpacing(10);

                    foreach (var i in Enumerable.Range(1, 3))
                    {
                        text.Span($"Paragraph {i}: ").SemiBold();
                        text.Line(Placeholders.Paragraph());
                    }
                });
            });
        }
コード例 #4
0
        public void Textcolumn()
        {
            RenderingTest
            .Create()
            .PageSize(PageSizes.A4)
            .ProducePdf()
            .ShowResults()
            .Render(container =>
            {
                container
                .Padding(20)
                .Padding(10)
                .MinimalBox()
                .Border(1)
                .Padding(5)
                .Padding(10)
                .Text(text =>
                {
                    text.DefaultTextStyle(TextStyle.Default);
                    text.AlignLeft();
                    text.ParagraphSpacing(10);

                    foreach (var i in Enumerable.Range(1, 100))
                    {
                        text.Line($"{i}: {Placeholders.Paragraph()}");
                    }
                });
            });
        }
コード例 #5
0
        public void HugeList()
        {
            RenderingTest
            .Create()
            .PageSize(PageSizes.A4)
            .ProducePdf()
            .ShowResults()
            .Render(container =>
            {
                container
                .Padding(20)
                .Padding(10)
                .MinimalBox()
                .Border(1)
                .Padding(5)
                .Padding(10)
                .Text(text =>
                {
                    text.DefaultTextStyle(TextStyle.Default.FontSize(20));
                    text.AlignLeft();
                    text.ParagraphSpacing(10);

                    text.Span("This text is a normal text, ");
                    text.Span("this is a bold text, ").Bold();
                    text.Span("this is a red and underlined text, ").FontColor(Colors.Red.Medium).Underline();
                    text.Span("and this is slightly bigger text.").FontSize(16);

                    text.Span("The new text element also supports injecting custom content between words: ");
                    text.Element().PaddingBottom(-4).Height(16).Width(32).Image(Placeholders.Image);
                    text.Span(".");

                    text.EmptyLine();

                    foreach (var i in Enumerable.Range(1, 100))
                    {
                        text.Line($"{i}: {Placeholders.Paragraph()}");

                        text.Hyperlink("Please visit QuestPDF website", "https://www.questpdf.com");

                        text.Span("This is page number ");
                        text.CurrentPageNumber();
                        text.Span(" out of ");
                        text.TotalPages();

                        text.EmptyLine();
                    }
                });
            });
        }
コード例 #6
0
ファイル: ShowOnceExample.cs プロジェクト: lmingle/library
        public void ShowOnce()
        {
            RenderingTest
            .Create()
            .ProduceImages()
            .ShowResults()
            .RenderDocument(container =>
            {
                container.Page(page =>
                {
                    page.Margin(20);
                    page.Size(PageSizes.A7.Landscape());
                    page.PageColor(Colors.White);

                    page.Header().Text("With show once").SemiBold();

                    page.Content().PaddingVertical(5).Row(row =>
                    {
                        row.RelativeItem()
                        .Background(Colors.Grey.Lighten2)
                        .Border(1)
                        .Padding(5)
                        .ShowOnce()
                        .Text(Placeholders.Label());

                        row.RelativeItem(2)
                        .Border(1)
                        .Padding(5)
                        .Text(Placeholders.Paragraph());
                    });

                    page.Footer().Text(text =>
                    {
                        text.Span("Page ");
                        text.CurrentPageNumber();
                        text.Span(" out of ");
                        text.TotalPages();
                    });
                });
            });
        }
コード例 #7
0
        public void RotateInTable()
        {
            RenderingTest
            .Create()
            .PageSize(200, 200)
            .Render(container =>
            {
                container
                .Padding(10)
                .Border(2)
                .Row(row =>
                {
                    row.ConstantItem(25)
                    .Border(1)
                    .RotateLeft()
                    .AlignCenter()
                    .AlignMiddle()
                    .Text("Sample text");

                    row.RelativeItem().Border(1).Padding(5).Text(Placeholders.Paragraph());
                });
            });
        }
コード例 #8
0
ファイル: FrameExample.cs プロジェクト: lmingle/library
 public void Frame()
 {
     RenderingTest
     .Create()
     .PageSize(550, 400)
     .ShowResults()
     .Render(container =>
     {
         container
         .Background("#FFF")
         .Padding(25)
         .Column(column =>
         {
             for (var i = 1; i <= 4; i++)
             {
                 column.Item().Row(row =>
                 {
                     row.RelativeItem(2).LabelCell(Placeholders.Label());
                     row.RelativeItem(3).ValueCell().Text(Placeholders.Paragraph());
                 });
             }
         });
     });
 }
コード例 #9
0
ファイル: TableExamples.cs プロジェクト: lmingle/library
        public static void GeneratePerformanceStructure(IContainer container, int repeats)
        {
            container
            .Padding(25)
            //.Background(Colors.Blue.Lighten2)
            .MinimalBox()
            .Border(1)
            //.Background(Colors.Red.Lighten2)
            .Table(table =>
            {
                table.ColumnsDefinition(columns =>
                {
                    columns.ConstantColumn(100);
                    columns.RelativeColumn();
                    columns.ConstantColumn(100);
                    columns.RelativeColumn();
                });

                table.ExtendLastCellsToTableBottom();

                foreach (var i in Enumerable.Range(0, repeats))
                {
                    table.Cell().RowSpan(3).LabelCell("Project");
                    table.Cell().RowSpan(3).ShowEntire().ValueCell(Placeholders.Sentence());

                    table.Cell().LabelCell("Report number");
                    table.Cell().ValueCell(i.ToString());

                    table.Cell().LabelCell("Date");
                    table.Cell().ValueCell(Placeholders.ShortDate());

                    table.Cell().LabelCell("Inspector");
                    table.Cell().ValueCell("Marcin Ziąbek");

                    table.Cell().ColumnSpan(2).LabelCell("Morning weather");
                    table.Cell().ColumnSpan(2).LabelCell("Evening weather");

                    table.Cell().ValueCell("Time");
                    table.Cell().ValueCell("7:13");

                    table.Cell().ValueCell("Time");
                    table.Cell().ValueCell("18:25");

                    table.Cell().ValueCell("Description");
                    table.Cell().ValueCell("Sunny");

                    table.Cell().ValueCell("Description");
                    table.Cell().ValueCell("Windy");

                    table.Cell().ValueCell("Wind");
                    table.Cell().ValueCell("Mild");

                    table.Cell().ValueCell("Wind");
                    table.Cell().ValueCell("Strong");

                    table.Cell().ValueCell("Temperature");
                    table.Cell().ValueCell("17°C");

                    table.Cell().ValueCell("Temperature");
                    table.Cell().ValueCell("32°C");

                    table.Cell().LabelCell("Remarks");
                    table.Cell().ColumnSpan(3).ValueCell(Placeholders.Paragraph());
                }
            });
        }
コード例 #10
0
        public static ReportModel GetReport()
        {
            return(new ReportModel
            {
                Title = "Sample Report Document",
                HeaderFields = HeaderFields(),

                LogoData = Helpers.GetImage("Logo.png"),
                Sections = Enumerable.Range(0, 40).Select(x => GenerateSection()).ToList(),
                Photos = Enumerable.Range(0, 25).Select(x => GetReportPhotos()).ToList()
            });

            List <ReportHeaderField> HeaderFields()
            {
                return(new List <ReportHeaderField>
                {
                    new ReportHeaderField()
                    {
                        Label = "Scope",
                        Value = "Internal activities"
                    },
                    new ReportHeaderField()
                    {
                        Label = "Author",
                        Value = "Marcin Ziąbek"
                    },
                    new ReportHeaderField()
                    {
                        Label = "Date",
                        Value = DateTime.Now.ToString("g")
                    },
                    new ReportHeaderField()
                    {
                        Label = "Status",
                        Value = "Completed, found 2 issues"
                    }
                });
            }

            ReportSection GenerateSection()
            {
                var sectionLength = Helpers.Random.NextDouble() > 0.75
                    ? Helpers.Random.Next(20, 40)
                    : Helpers.Random.Next(5, 10);

                return(new ReportSection
                {
                    Title = Placeholders.Label(),
                    Parts = Enumerable.Range(0, sectionLength).Select(x => GetRandomElement()).ToList()
                });
            }

            ReportSectionElement GetRandomElement()
            {
                var random = Helpers.Random.NextDouble();

                if (random < 0.9f)
                {
                    return(GetTextElement());
                }

                if (random < 0.95f)
                {
                    return(GetMapElement());
                }

                return(GetPhotosElement());
            }

            ReportSectionText GetTextElement()
            {
                return(new ReportSectionText
                {
                    Label = Placeholders.Label(),
                    Text = Placeholders.Paragraph()
                });
            }

            ReportSectionMap GetMapElement()
            {
                return(new ReportSectionMap
                {
                    Label = "Location",
                    Location = Helpers.RandomLocation()
                });
            }

            ReportSectionPhotos GetPhotosElement()
            {
                return(new ReportSectionPhotos
                {
                    Label = "Photos",
                    PhotoCount = Helpers.Random.Next(1, 15)
                });
            }

            ReportPhoto GetReportPhotos()
            {
                return(new ReportPhoto()
                {
                    Comments = Placeholders.Sentence(),
                    Date = DateTime.Now - TimeSpan.FromDays(Helpers.Random.NextDouble() * 100),
                    Location = Helpers.RandomLocation()
                });
            }
        }