Last active
February 25, 2023 19:41
-
-
Save hahmed/89289dd4d8879e353cdc to your computer and use it in GitHub Desktop.
Ecrion Template rendering
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class LocalTemplateRenderer : ITemplateRenderer | |
{ | |
public byte[] ToPdf(System.Xml.Linq.XDocument dataStructure, System.IO.Stream template) | |
{ | |
// Prepare rendering parameters | |
var _param = new RenderingParameters(); | |
var _output = new OutputInformation(); | |
_param.OutputFormat = Engine.OutputFormat.PDF; | |
_param.Template = new LocalDocumentTemplate(template, null, Engine.XsltEngine.MSXML, "en_EN", null); | |
var input = DataSource(dataStructure); | |
//output stream... | |
using (var outputStream = new MemoryStream()) | |
{ | |
Engine engine = new Engine(); | |
engine.Render(input, outputStream, _param, ref _output); | |
return outputStream.ToArray(); | |
} | |
} | |
/// <summary> | |
/// Get the data source | |
/// </summary> | |
/// <param name="data">Data structure</param> | |
/// <returns>IDataSource</returns> | |
private IDataSource DataSource(XDocument doc) | |
{ | |
var stream = new MemoryStream(); | |
doc.Save(stream); | |
stream.Position = 0; // Rewind the stream ready to read from it elsewhere | |
return new Ecrion.Ultrascale.XmlDataSource(stream, Engine.InputFormat.XML); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment