-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathPDFCreator.cs
More file actions
46 lines (43 loc) · 1.98 KB
/
PDFCreator.cs
File metadata and controls
46 lines (43 loc) · 1.98 KB
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
using HTMLQuestPDF.Extensions;
using QuestPDF.Fluent;
using QuestPDF.Helpers;
using QuestPDF.Infrastructure;
namespace HTMLToQPDF.Example.Utilities
{
internal static class PDFCreator
{
public static void Create(string html, string path, bool customStyles)
{
Document.Create(container =>
{
container.Page(page =>
{
page.Size(PageSizes.A4);
page.MarginHorizontal(0.5f, Unit.Centimetre);
page.MarginVertical(1f, Unit.Centimetre);
page.DefaultTextStyle(TextStyle.Default
.FontFamily("MS Reference Sans Serif")
.Fallback(y => y.FontFamily("MS Reference Sans Serif")
.Fallback(y => y.FontFamily("Segoe UI Emoji")
.Fallback(y => y.FontFamily("Microsoft YaHei")))));
page.Content().Column(col =>
{
col.Item().HTML(handler =>
{
if (customStyles)
{
handler.SetTextStyleForHtmlElement("h1", t => t.FontColor(Colors.DeepOrange.Accent4).FontSize(32).Bold());
handler.SetCssStyleForHtmlElement("underline", t => t.Underline());
handler.SetContainerStyleForHtmlElement("div", c => c.Background(Colors.Teal.Lighten5));
handler.SetContainerStyleForHtmlElement("img", c => c.MaxHeight(7, Unit.Centimetre));
handler.SetContainerStyleForHtmlElement("table", c => c.Background(Colors.Pink.Lighten5));
handler.SetListVerticalPadding(40);
}
handler.SetHtml(html);
});
});
});
}).GeneratePdf(path);
}
}
}