本文整理汇总了C#中Engine.Render方法的典型用法代码示例。如果您正苦于以下问题:C# Engine.Render方法的具体用法?C# Engine.Render怎么用?C# Engine.Render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Engine
的用法示例。
在下文中一共展示了Engine.Render方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Render
public TemplateResponse Render(RenderingOptions options)
{
if (options == null)
{
throw new FaultException<string>("Rendering options are null");
}
var _param = new RenderingParameters();
if (options.OutputFormat == OutputFormat.PDF)
{
_param.OutputFormat = Engine.OutputFormat.PDF;
_param.PDFOutputFlags = Engine.PDFFlags.PDF14;
}
else if (options.OutputFormat == OutputFormat.HTML)
{
_param.OutputFormat = Engine.OutputFormat.HTML;
_param.HtmlOutputSettings = new Engine.HtmlOutputSettings
{
GenerateHtmlDocument = false
};
}
else
{
// no other format is supported...
throw new FaultException<string>("Rendering.OutputFormat not supported");
}
var template = XDocument.Parse(options.Template);
Stream stream = new MemoryStream();
template.Save(stream);
// Rewind the stream ready to read from it elsewhere
stream.Position = 0;
_param.Template = new LocalDocumentTemplate(stream, null, Engine.XsltEngine.MSXML, "en_EN", null);
var _output = new OutputInformation();
var ds = DataSource(options);
using (var outputStream = new MemoryStream())
{
Engine engine = new Engine();
engine.Render(ds, outputStream, _param, ref _output);
return new TemplateResponse
{
Response = outputStream.ToArray()
};
}
}
示例2: GeneratePdf
/// <summary>
/// This method will generate Pdf file from HtmlDataSource property and will use
/// RenderingParameters as pdf file rendering parameters
/// </summary>
/// <param name="applicationId">Form applicatio id</param>
/// <param name="html">Html content to crete pdf</param>
public void GeneratePdf(int applicationId, string html)
{
this.HtmlDataSource = html;
this.PdfFileLocationPath = HostingEnvironment.MapPath(@"~/Content/pdfs");
if (string.IsNullOrEmpty(this.PdfFileLocationPath))
{
throw new ArgumentException("Specify pdf file saving location");
}
string outFilePath = Path.Combine(this.PdfFileLocationPath, applicationId.ToString());
#if DEBUG
// For testing purpose save html
File.WriteAllText(outFilePath + ".html", html);
#endif
using (FileStream outputStream = new FileStream(outFilePath + ".pdf", FileMode.Create))
{
OutputInformation outInfo = new OutputInformation();
var processInfo = new PdfCreateProcessInfo();
processInfo.OnMassageArrived += this.ProcessInfo_OnMassageArrived;
outInfo.NotificationEvents = processInfo;
var pdfEngine = new Engine();
pdfEngine.Render(this, outputStream, this.RenderingParameters, ref outInfo);
if (!this.IsError)
{
Attachment att = new Attachment
{
ApplicationFormId = applicationId,
AttachmentType = DbObjects.OLE.TableRefEnums.AttachmentType.PdfApplication,
Description = "pdf document",
FileName = applicationId.ToString(),
ServerFileName = "~/Content/pdfs/" + applicationId.ToString() + ".pdf"
};
this.databaseHelper.Create<Attachment>(att);
this.databaseHelper.FlushChanges();
}
}
}