-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathPDFCreator.cs
More file actions
52 lines (47 loc) · 2.17 KB
/
PDFCreator.cs
File metadata and controls
52 lines (47 loc) · 2.17 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
47
48
49
50
51
52
using HTMLToQPDF.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)
{
QuestPDF.Settings.License = LicenseType.Community;
Document.Create(container =>
{
container.Page(page =>
{
page.Size(PageSizes.A4);
page.MarginHorizontal(0.5f, Unit.Centimetre);
page.MarginVertical(1f, Unit.Centimetre);
#pragma warning disable CS0618 // Type or member is obsolete
page.DefaultTextStyle(TextStyle.Default.FontFamily("Arial").FontSize(8).Fallback(y => y.FontFamily("Segoe UI Emoji")));
#pragma warning restore CS0618
/* page.DefaultTextStyle(TextStyle.Default
// .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", TextStyle.Default.FontColor(Colors.DeepOrange.Accent4).FontSize(32).Bold());
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);
}
}
}