1111// "The Art of War"
1212
1313using PdfSharp ;
14+ using PdfSharp . Drawing ;
1415
1516namespace TheArtOfDev . HtmlRenderer . PdfSharp
1617{
@@ -26,6 +27,11 @@ public sealed class PdfGenerateConfig
2627 /// </summary>
2728 private PageSize _pageSize ;
2829
30+ /// <summary>
31+ /// if the page size is undefined this allow you to set manually the page size
32+ /// </summary>
33+ private XSize _xsize ;
34+
2935 /// <summary>
3036 /// the top margin between the page start and the text
3137 /// </summary>
@@ -58,6 +64,14 @@ public PageSize PageSize
5864 set { _pageSize = value ; }
5965 }
6066
67+ /// <summary>
68+ /// if the page size is undefined this allow you to set manually the page size
69+ /// </summary>
70+ public XSize ManualPageSize {
71+ get { return _xsize ; }
72+ set { _xsize = value ; }
73+ }
74+
6175 /// <summary>
6276 /// the top margin between the page start and the text
6377 /// </summary>
@@ -119,5 +133,29 @@ public void SetMargins(int value)
119133 if ( value > - 1 )
120134 _marginBottom = _marginLeft = _marginTop = _marginRight = value ;
121135 }
136+
137+ // The international definitions are:
138+ // 1 inch == 25.4 mm
139+ // 1 inch == 72 point
140+
141+ /// <summary>
142+ /// Convert the units passed in milimiters to the units used in PdfSharp
143+ /// </summary>
144+ /// <param name="width"></param>
145+ /// <param name="height"></param>
146+ /// <returns></returns>
147+ public static XSize MilimitersToUnits ( double width , double height ) {
148+ return new XSize ( width / 25.4 * 72 , height / 25.4 * 72 ) ;
149+ }
150+
151+ /// <summary>
152+ /// Convert the units passed in inches to the units used in PdfSharp
153+ /// </summary>
154+ /// <param name="width"></param>
155+ /// <param name="height"></param>
156+ /// <returns></returns>
157+ public static XSize InchesToUnits ( double width , double height ) {
158+ return new XSize ( width * 72 , height * 72 ) ;
159+ }
122160 }
123161}
0 commit comments