-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathProgram.cs
More file actions
108 lines (86 loc) · 3.58 KB
/
Program.cs
File metadata and controls
108 lines (86 loc) · 3.58 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using MigraDoc.DocumentObjectModel;
using MigraDoc.Extensions.Markdown;
using MigraDoc.Rendering;
using System.Diagnostics;
using System.IO;
namespace MigraDoc.Extensions.Html.Example
{
class Program
{
static void Main(string[] args)
{
new Program().Run();
}
private string outputName = "output.pdf";
void Run()
{
if (File.Exists(outputName))
{
File.Delete(outputName);
}
var doc = new Document();
StyleDoc(doc);
var section = doc.AddSection();
var html = File.ReadAllText("example.html");
section.AddHtml(html);
var markdown = File.ReadAllText("example.md");
section.AddMarkdown(markdown);
var renderer = new PdfDocumentRenderer();
renderer.Document = doc;
renderer.RenderDocument();
renderer.Save(outputName);
Process.Start(outputName);
}
private void StyleDoc(Document doc)
{
Color green = new Color(108, 179, 63),
brown = new Color(88, 71, 76),
lightbrown = new Color(150, 132, 126);
var body = doc.Styles["Normal"];
body.Font.Size = Unit.FromPoint(10);
body.Font.Color = new Color(51, 51, 51);
body.ParagraphFormat.LineSpacingRule = LineSpacingRule.Multiple;
body.ParagraphFormat.LineSpacing = 1.25;
body.ParagraphFormat.SpaceAfter = 10;
var footer = doc.Styles["Footer"];
footer.Font.Size = Unit.FromPoint(9);
footer.Font.Color = lightbrown;
var h1 = doc.Styles["Heading1"];
h1.Font.Color = brown;
h1.Font.Bold = true;
h1.Font.Size = Unit.FromPoint(15);
var h2 = doc.Styles["Heading2"];
h2.Font.Color = green;
h2.Font.Bold = true;
h2.Font.Size = Unit.FromPoint(13);
var h3 = doc.Styles["Heading3"];
h3.Font.Bold = true;
h3.Font.Color = Colors.Black;
h3.Font.Size = Unit.FromPoint(11);
var links = doc.Styles["Hyperlink"];
links.Font.Color = green;
var unorderedlist = doc.AddStyle("UnorderedList", "Normal");
var listInfo = new ListInfo();
listInfo.ListType = ListType.BulletList1;
unorderedlist.ParagraphFormat.ListInfo = listInfo;
unorderedlist.ParagraphFormat.LeftIndent = "1cm";
unorderedlist.ParagraphFormat.FirstLineIndent = "-0.5cm";
unorderedlist.ParagraphFormat.SpaceAfter = 0;
var orderedlist = doc.AddStyle("OrderedList", "UnorderedList");
orderedlist.ParagraphFormat.ListInfo.ListType = ListType.NumberList1;
// for list spacing (since MigraDoc doesn't provide a list object that we can target)
var listStart = doc.AddStyle("ListStart", "Normal");
listStart.ParagraphFormat.SpaceAfter = 0;
listStart.ParagraphFormat.LineSpacing = 0.5;
var listEnd = doc.AddStyle("ListEnd", "ListStart");
listEnd.ParagraphFormat.LineSpacing = 1;
var hr = doc.AddStyle("HorizontalRule", "Normal");
var hrBorder = new Border();
hrBorder.Width = "1pt";
hrBorder.Color = Colors.DarkGray;
hr.ParagraphFormat.Borders.Bottom = hrBorder;
hr.ParagraphFormat.LineSpacing = 0;
hr.ParagraphFormat.SpaceBefore = 15;
}
}
}