-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.vb
More file actions
59 lines (55 loc) · 3.22 KB
/
Program.vb
File metadata and controls
59 lines (55 loc) · 3.22 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
Imports DevExpress.Drawing
Imports DevExpress.XtraRichEdit
Imports DevExpress.XtraRichEdit.API.Native
Imports System.Drawing
Friend Module Program
Public Function Main(ByVal args As String()) As Integer
Try
' Use the Skia Drawing Engine
Settings.DrawingEngine = DrawingEngine.Skia
Dim fileName As String = Path.Combine(AppContext.BaseDirectory, "fontTest.docx")
' Include Fonts in the Application
Dim fonts As String() = _("Inter-Regular.ttf", "NotoSans-Regular.ttf")
''' Cannot convert LocalDeclarationStatementSyntax, System.InvalidCastException: Unable to cast object of type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.EmptyStatementSyntax' to type 'Microsoft.CodeAnalysis.VisualBasic.Syntax.ExpressionSyntax'.
''' at ICSharpCode.CodeConverter.VB.CommonConversions.RemodelVariableDeclaration(VariableDeclarationSyntax declaration) in C:\builds\CS2VB\CodeConverter-master\CodeConverter\VB\CommonConversions.cs:line 478
''' at ICSharpCode.CodeConverter.VB.MethodBodyExecutableStatementVisitor.VisitLocalDeclarationStatement(LocalDeclarationStatementSyntax node) in C:\builds\CS2VB\CodeConverter-master\CodeConverter\VB\MethodBodyExecutableStatementVisitor.cs:line 59
''' at Microsoft.CodeAnalysis.CSharp.CSharpSyntaxVisitor`1.Visit(SyntaxNode node)
''' at ICSharpCode.CodeConverter.VB.CommentConvertingMethodBodyVisitor.DefaultVisit(SyntaxNode node) in C:\builds\CS2VB\CodeConverter-master\CodeConverter\VB\CommentConvertingMethodBodyVisitor.cs:line 24
'''
''' Input:
''' string[] fontFiles = [.. fonts.Select(f => Path.Combine(AppContext.BaseDirectory, f))];
'''
''' ' Register fonts before loading documents
For Each fp In fontFiles
Call DXFontRepository.Instance.AddFont(fp)
Next
Using wordProcessor = New RichEditDocumentServer()
Dim doc As Document = wordProcessor.Document
doc.AppendText("This document is generated by Word Processing Document API: Inter font" & Microsoft.VisualBasic.Constants.vbCrLf)
Dim cp As CharacterProperties = 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")
Dim cp1 As CharacterProperties = doc.BeginUpdateCharacters(doc.Paragraphs(1).Range)
cp1.FontName = "Noto Sans"
doc.EndUpdateCharacters(cp1)
wordProcessor.SaveDocument(fileName, DocumentFormat.Docx)
Dim exportedPdf = New MemoryStream()
wordProcessor.ExportToPdf(exportedPdf)
exportedPdf.Position = 0
Dim ouput = Console.OpenStandardOutput()
exportedPdf.CopyTo(ouput)
ouput.Flush()
Program.Log("Done.")
Return 0
End Using
Catch e As Exception
Program.Log("ERROR:")
Log(e.ToString())
Return 1
End Try
End Function
Private Sub Log(ByVal message As String)
Console.Error.WriteLine($"[{DateTimeOffset.UtcNow:O}] {message}")
End Sub
End Module