-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
59 lines (51 loc) · 2.24 KB
/
Program.cs
File metadata and controls
59 lines (51 loc) · 2.24 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
using DevExpress.Drawing;
using DevExpress.XtraRichEdit;
using DevExpress.XtraRichEdit.API.Native;
using System.Drawing;
using System.Runtime.InteropServices;
internal static class Program {
public static int Main(string[] args) {
try {
// Use the Skia Drawing Engine
Settings.DrawingEngine = DrawingEngine.Skia;
string fileName = Path.Combine(AppContext.BaseDirectory, "fontTest.docx");
// Include Fonts in the Application
string[] fonts = ["Inter-Regular.ttf", "NotoSans-Regular.ttf"];
string[] fontFiles = [.. fonts.Select(f => Path.Combine(AppContext.BaseDirectory, f))];
// Register fonts before loading documents
foreach (var fp in fontFiles) {
DXFontRepository.Instance.AddFont(fp);
}
using (var wordProcessor = new RichEditDocumentServer())
{
Document doc = wordProcessor.Document;
doc.AppendText("This document is generated by Word Processing Document API: Inter font\r\n");
CharacterProperties cp =
doc.BeginUpdateCharacters(doc.Paragraphs[0].Range);
cp.FontName = "Inter";
doc.EndUpdateCharacters(cp);
doc.AppendText("This document is generated by Word Processing Document API: NotoSans font");
CharacterProperties cp1 =
doc.BeginUpdateCharacters(doc.Paragraphs[1].Range);
cp1.FontName = "Noto Sans";
doc.EndUpdateCharacters(cp1);
wordProcessor.SaveDocument(fileName, DocumentFormat.Docx);
using var exportedPdf = new MemoryStream();
wordProcessor.ExportToPdf(exportedPdf);
exportedPdf.Position = 0;
using var ouput = Console.OpenStandardOutput();
exportedPdf.CopyTo(ouput);
ouput.Flush();
Log("Done.");
return 0;
}
}
catch (Exception e) {
Log("ERROR:");
Log(e.ToString());
return 1;
}
}
private static void Log(string message) =>
Console.Error.WriteLine($"[{DateTimeOffset.UtcNow:O}] {message}");
}