Cover.cs 2.57 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using iText.IO.Image;
using iText.Kernel.Geom;
using iText.Layout;
using iText.Layout.Element;
using iText.Layout.Properties;
using PDFGenerator.Models;
using PDFGenerator.Utilities;
using System;
using static PDFGenerator.Utilities.Conversion;


namespace PDFGenerator.EvaluationReport
{
    public class Cover : BaseSection
    {
        private PDFCover PDFCover { get; }

        public Cover(PDFCover cover, Document document, Bookmarks bookmarks, TableOfContents tableOfContents)
        : base(document, bookmarks, tableOfContents)
        {
            PDFCover = cover;
        }

        /// <summary>
        /// Renders the content for the cover section.
        /// </summary>
        public override void Render()
        {
            int count = 0;
            ImageData imageData = ImageDataFactory.Create(PDFCover.Logo);
            Image image = new Image(imageData);
            PageSize pageSize = GetPageSize();

            image.ScaleAbsolute(MillimetersToPoints(60), MillimetersToPoints(16));
            image.SetFixedPosition(
                pageSize.GetRight() - image.GetImageScaledWidth() - MillimetersToPoints(5),
                pageSize.GetTop() - image.GetImageScaledHeight() - MillimetersToPoints(8)
            );

            Document.Add(image);

            Text text = new Text(PDFCover.Titles[count++]).AddStyle(Styles.Title);
            Document.Add(new Paragraph(text).SetFixedLeading(425).SetTextAlignment(TextAlignment.CENTER));

            Paragraph p = new Paragraph().SetMarginTop(-180f).SetMultipliedLeading(1.1f).SetTextAlignment(TextAlignment.CENTER);
            p.Add(new Text(PDFCover.Titles[count++]).AddStyle(Styles.Subtitle));
            p.Add(NewLine);
            p.Add(new Text(PDFCover.Titles[count++]).AddStyle(Styles.Subtitle));
            p.Add(NewLine);
            p.Add(new Text(PDFCover.Titles[count++]).AddStyle(Styles.Subtitle));
            p.Add(NewLine).Add(NewLine).Add(NewLine);
            p.Add(new Text(PDFCover.Titles[count++]).AddStyle(Styles.Subtitle));
            Document.Add(p);

            p = new Paragraph().SetMarginTop(0).SetMultipliedLeading(1.3f).SetTextAlignment(TextAlignment.CENTER);
            PDFCover.Titles.GetRange(count, PDFCover.Titles.Count - count)
            .ForEach(title =>
            {
                p.Add(new Text(title).AddStyle(Styles.SubsubtitleSubject));
                p.Add(NewLine);
            });

            p.Add(NewLine);
            p.Add(new Text(DateTime.Now.ToString("dd.MM.yyyy")).AddStyle(Styles.Subsubtitle));

            Document.Add(p);

            AddPageBreak();
        }
    }
}