Exemple #1
0
        private void ComposeBook(IDocumentContainer container, ICollection <BookChapter> chapters)
        {
            var subtitleStyle = TextStyle.Default.Size(24).SemiBold().Color(Colors.Blue.Medium);
            var normalStyle   = TextStyle.Default.Size(14);

            container.Page(page =>
            {
                page.Margin(50);

                page.Content().Column(column =>
                {
                    column.Item().Element(Title);
                    column.Item().PageBreak();
                    column.Item().Element(TableOfContents);
                    column.Item().PageBreak();

                    Chapters(column);

                    column.Item().Element(Acknowledgements);
                });

                page.Footer().Element(Footer);
            });

            void Title(IContainer container)
            {
                container
                .Extend()
                .PaddingBottom(200)
                .AlignBottom()
                .Column(column =>
                {
                    column.Item().Text("Quo Vadis").FontSize(72).Bold().FontColor(Colors.Blue.Darken2);
                    column.Item().Text("Henryk Sienkiewicz").FontSize(24).FontColor(Colors.Grey.Darken2);
                });
            }

            void TableOfContents(IContainer container)
            {
                container.Column(column =>
                {
                    SectionTitle(column, "Spis treści");

                    foreach (var chapter in chapters)
                    {
                        column.Item().InternalLink(chapter.Title).Row(row =>
                        {
                            row.RelativeItem().Text(chapter.Title).Style(normalStyle);
                            row.ConstantItem(100).AlignRight().Text(text => text.BeginPageNumberOfSection(chapter.Title).Style(normalStyle));
                        });
                    }
                });
            }

            void Chapters(ColumnDescriptor column)
            {
                foreach (var chapter in chapters)
                {
                    column.Item().Element(container => Chapter(container, chapter.Title, chapter.Content));
                }
            }

            void Chapter(IContainer container, string title, string content)
            {
                container.Column(column =>
                {
                    SectionTitle(column, title);

                    column.Item().Text(text =>
                    {
                        text.ParagraphSpacing(5);
                        text.Span(content).Style(normalStyle);
                    });

                    column.Item().PageBreak();
                });
            }

            void Acknowledgements(IContainer container)
            {
                container.Column(column =>
                {
                    SectionTitle(column, "Podziękowania");

                    column.Item().Text(text =>
                    {
                        text.DefaultTextStyle(normalStyle);

                        text.Span("Ten dokument został wygenerowany na podstawie książki w formacie TXT opublikowanej w serwisie ");
                        text.Hyperlink("wolnelektury.pl", "https://wolnelektury.pl/").FontColor(Colors.Blue.Medium).Underline();
                        text.Span(". Dziękuję za wspieranie polskiego czytelnictwa!");
                    });
                });
            }

            void SectionTitle(ColumnDescriptor column, string text)
            {
                column.Item().Location(text).Text(text).Style(subtitleStyle);
                column.Item().PaddingTop(10).PaddingBottom(50).BorderBottom(1).BorderColor(Colors.Grey.Lighten2).ExtendHorizontal();
            }

            void Footer(IContainer container)
            {
                container
                .AlignCenter()
                .Text(text =>
                {
                    text.CurrentPageNumber();
                    text.Span(" / ");
                    text.TotalPages();
                });
            }
        }