Scripts or expressions (the two terms are used interchangeably here) can be used in various places throughout the document. An expression can be marked by surrounding it with square brackets.
This is depicted in the following code:
C# |
Copy Code
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); doc.Body.Children.Add(new RenderText("2 + 2 = [2+2]")); |
In this case, the "[2+2]" is interpreted as an expression, and calculated to produce the resulting text.
The language used in expressions is determined by the C1PrintDocument.ScriptingOptions.Language property. It can have one of two possible values:
The ScriptLanguageEnum enumeration enumerates the languages which can be used in C1.C1Preview.C1PrintDocument scripts.
This code snippet below depicts adding CSharp language used in expressions in the document.
C# |
Copy Code
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); doc.ScriptingOptions.Language = ScriptLanguageEnum.CSharp; RenderText rt = new RenderText("[PageNo == 1 ? \"First\" : \"Not first\"]"); doc.Body.Children.Add(rt); |
By default, the following assemblies are available for scripts:
To add another system or custom assembly to the list of assemblies referenced in the scripts, use the C1PrintDocument.ScriptingOptions.ExternalAssemblies property. For instance, the following will add a reference to the System.Data assembly to the document's scripts:
C# |
Copy Code
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); doc.ScriptingOptions.ExternalAssemblies.Add("System.Data.dll"); |
The following namespaces are by default available (imported) for use in scripts:
To add another namespace, use the C1PrintDocument.ScriptingOptions.Namespaces property. For instance, this will allow the use of types declared in System.Data namespace in the document's scripts without fully qualifying them with the namespace:
C# |
Copy Code
|
---|---|
C1PrintDocument doc = new C1PrintDocument(); doc.ScriptingOptions. Namespaces.Add("System.Data"); |