forked from empira/PDFsharp-1.5
/
Samples.cs
125 lines (104 loc) · 3.81 KB
/
Samples.cs
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
using NUnit.Framework;
using PdfSharp.Drawing;
using PdfSharp.Fonts;
using PdfSharp.Internal;
using PdfSharp.Pdf;
using PdfSharp.Tests.Utils;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace PdfSharp.Tests
{
[TestFixture]
public class Samples
{
private Uri _outputFolder = null;
private string _extOuput = ".pdf";
[SetUp]
public void Prepare2Tests()
{
if (_outputFolder == null)
{
_outputFolder = GeneralUtils.OutputTestsFolder();
}
Directory.CreateDirectory(_outputFolder.LocalPath);
}
private static readonly object[] TestCasesHelloWorld =
{
new object[]{"Arial",
20,
XFontStyle.BoldItalic },
new object[]{"Arial",
20,
XFontStyle.Bold },
new object[]{"Arial",
20,
XFontStyle.Regular },
new object[]{"Arial",
20,
XFontStyle.Italic },
new object[]{"Courier New",
20,
XFontStyle.BoldItalic },
new object[]{"Courier New",
20,
XFontStyle.Bold },
new object[]{"Courier New",
20,
XFontStyle.Italic },
new object[]{"Courier New",
20,
XFontStyle.Regular },
new object[]{"Times New Roman",
20,
XFontStyle.BoldItalic },
new object[]{"Times New Roman",
20,
XFontStyle.Bold },
new object[]{"Times New Roman",
20,
XFontStyle.Italic },
new object[]{"Times New Roman",
20,
XFontStyle.Regular },
};
[Test, TestCaseSource("TestCasesHelloWorld")]
public void HelloWorld(string familyName, double fontSize, XFontStyle style)
{
string filename = "HelloWorld";
// Create a new PDF document.
var document = new PdfDocument();
document.Info.Title = "Created with PDFsharp";
// Create an empty page in this document.
var page = document.AddPage();
// Get an XGraphics object for drawing on this page.
var gfx = XGraphics.FromPdfPage(page);
// Draw two lines with a red default pen.
var width = page.Width;
var height = page.Height;
gfx.DrawLine(XPens.Red, 0, 0, width, height);
gfx.DrawLine(XPens.Red, width, 0, 0, height);
// Draw a circle with a red pen which is 1.5 point thick.
var r = width / 5;
gfx.DrawEllipse(new XPen(XColors.Red, 1.5), XBrushes.White, new XRect(width / 2 - r, height / 2 - r, 2 * r, 2 * r));
// Create a font
var font = new XFont(familyName, fontSize, style);
// Draw the text.
gfx.DrawString("Hello, PDFsharp!", font, XBrushes.Black,
new XRect(0, 0, page.Width, page.Height), XStringFormats.Center);
string fileNameOut = string.Format("{0}_{1}_{2}_{3}{4}",
filename,
familyName,
fontSize,
style,
_extOuput);
string fullOutputPath = System.IO.Path.Combine(_outputFolder.LocalPath, fileNameOut);
// Save the document...
document.Save(fullOutputPath);
}
}
}