forked from ArthurHub/HTML-Renderer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPdfGenerateConfig.cs
More file actions
175 lines (153 loc) · 4.75 KB
/
Copy pathPdfGenerateConfig.cs
File metadata and controls
175 lines (153 loc) · 4.75 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
// "Therefore those skilled at the unorthodox
// are infinite as heaven and earth,
// inexhaustible as the great rivers.
// When they come to an end,
// they begin again,
// like the days and months;
// they die and are reborn,
// like the four seasons."
//
// - Sun Tsu,
// "The Art of War"
using PdfSharp;
using PdfSharp.Drawing;
namespace TheArtOfDev.HtmlRenderer.PdfSharp
{
/// <summary>
/// The settings for generating PDF using <see cref="PdfGenerator"/>
/// </summary>
public sealed class PdfGenerateConfig
{
#region Fields/Consts
/// <summary>
/// the page size to use for each page in the generated pdf
/// </summary>
private PageSize _pageSize;
/// <summary>
/// if the page size is undefined this allow you to set manually the page size
/// </summary>
private XSize _xsize;
/// <summary>
/// the orientation of each page of the generated pdf
/// </summary>
private PageOrientation _pageOrientation;
/// <summary>
/// the top margin between the page start and the text
/// </summary>
private int _marginTop;
/// <summary>
/// the bottom margin between the page end and the text
/// </summary>
private int _marginBottom;
/// <summary>
/// the left margin between the page start and the text
/// </summary>
private int _marginLeft;
/// <summary>
/// the right margin between the page end and the text
/// </summary>
private int _marginRight;
#endregion
/// <summary>
/// the page size to use for each page in the generated pdf
/// </summary>
public PageSize PageSize
{
get { return _pageSize; }
set { _pageSize = value; }
}
/// <summary>
/// if the page size is undefined this allow you to set manually the page size
/// </summary>
public XSize ManualPageSize {
get { return _xsize; }
set { _xsize = value; }
}
/// <summary>
/// the orientation of each page of the generated pdf
/// </summary>
public PageOrientation PageOrientation
{
get { return _pageOrientation; }
set { _pageOrientation = value; }
}
/// <summary>
/// the top margin between the page start and the text
/// </summary>
public int MarginTop
{
get { return _marginTop; }
set
{
if (value > -1)
_marginTop = value;
}
}
/// <summary>
/// the bottom margin between the page end and the text
/// </summary>
public int MarginBottom
{
get { return _marginBottom; }
set
{
if (value > -1)
_marginBottom = value;
}
}
/// <summary>
/// the left margin between the page start and the text
/// </summary>
public int MarginLeft
{
get { return _marginLeft; }
set
{
if (value > -1)
_marginLeft = value;
}
}
/// <summary>
/// the right margin between the page end and the text
/// </summary>
public int MarginRight
{
get { return _marginRight; }
set
{
if (value > -1)
_marginRight = value;
}
}
/// <summary>
/// Set all 4 margins to the given value.
/// </summary>
/// <param name="value"></param>
public void SetMargins(int value)
{
if (value > -1)
_marginBottom = _marginLeft = _marginTop = _marginRight = value;
}
// The international definitions are:
// 1 inch == 25.4 mm
// 1 inch == 72 point
/// <summary>
/// Convert the units passed in milimiters to the units used in PdfSharp
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <returns></returns>
public static XSize MilimitersToUnits(double width, double height) {
return new XSize(width / 25.4 * 72, height / 25.4 * 72);
}
/// <summary>
/// Convert the units passed in inches to the units used in PdfSharp
/// </summary>
/// <param name="width"></param>
/// <param name="height"></param>
/// <returns></returns>
public static XSize InchesToUnits(double width, double height) {
return new XSize(width * 72, height * 72);
}
}
}