-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathProgram.cs
More file actions
70 lines (65 loc) · 2.3 KB
/
Copy pathProgram.cs
File metadata and controls
70 lines (65 loc) · 2.3 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
using jsreport.Binary;
using jsreport.Local;
using jsreport.Types;
using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
namespace ConsoleApp
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Initializing local jsreport.exe utility");
var rs = new LocalReporting()
.RunInDirectory(Path.Combine(Directory.GetCurrentDirectory(), "jsreport"))
.KillRunningJsReportProcesses()
.UseBinary(JsReportBinary.GetBinary())
.Configure(cfg => cfg.DoTrustUserCode().FileSystemStore().BaseUrlAsWorkingDirectory())
.AsUtility()
.Create();
Console.WriteLine("Rendering localy stored template jsreport/data/templates/Invoice into invoice.pdf");
var invoiceReport = rs.RenderByNameAsync("Invoice", InvoiceData).Result;
invoiceReport.Content.CopyTo(File.OpenWrite("invoice.pdf"));
Console.WriteLine("Rendering custom report fully described through the request object into customReport.pdf");
var customReport = rs.RenderAsync(CustomRenderRequest).Result;
customReport.Content.CopyTo(File.OpenWrite("customReport.pdf"));
Console.WriteLine("Done, hit any key...");
Console.ReadKey();
}
private static RenderRequest CustomRenderRequest = new RenderRequest()
{
Template = new Template()
{
Content = "Helo world from {{message}}",
Engine = Engine.Handlebars,
Recipe = Recipe.ChromePdf
},
Data = new
{
message = "jsreport for .NET!!!"
}
};
static object InvoiceData = new
{
number = "123",
seller = new
{
name = "Next Step Webs, Inc.",
road = "12345 Sunny Road",
country = "Sunnyville, TX 12345"
},
buyer = new
{
name = "Acme Corp.",
road = "16 Johnson Road",
country = "Paris, France 8060"
},
items = new[]
{
new { name = "Website design", price = 300 }
}
};
}
}