本文整理汇总了C#中iTextSharp.tool.xml.parser.XMLParser.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# XMLParser.Flush方法的具体用法?C# XMLParser.Flush怎么用?C# XMLParser.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iTextSharp.tool.xml.parser.XMLParser
的用法示例。
在下文中一共展示了XMLParser.Flush方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: iTextSharp
private void iTextSharp(string html)
{
System.Web.HttpContext.Current.Response.ContentType = "application/pdf";
System.Web.HttpContext.Current.Response.AddHeader("content-disposition", "attachment;filename=BookingDetails.pdf");
System.Web.HttpContext.Current.Response.Cache.SetCacheability(HttpCacheability.NoCache);
Document pdfDoc = new Document(new Rectangle(922, 1296), 7f, 7f, 7f, 0f);
PdfWriter writer = PdfWriter.GetInstance(pdfDoc, System.Web.HttpContext.Current.Response.OutputStream);
pdfDoc.Open();
HtmlPipelineContext htmlContext = new HtmlPipelineContext(null);
htmlContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
ICssFile cfile = new CssFileImpl();
ICSSResolver cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(false);
cssResolver.AddCssFile(System.Web.Hosting.HostingEnvironment.ApplicationPhysicalPath + @"App_Data\PDF.all.min.css", true);
//Pipeline
IPipeline pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlContext, new PdfWriterPipeline(pdfDoc, writer)));
//XMLWorker
XMLWorker worker = new XMLWorker(pipeline, true);
XMLParser parser = new XMLParser();
parser.AddListener(worker);
using (TextReader sr = new StringReader(html))
{
parser.Parse(sr);
}
parser.Flush();
pdfDoc.Close();
System.Web.HttpContext.Current.Response.Write(pdfDoc);
System.Web.HttpContext.Current.ApplicationInstance.CompleteRequest();
}
示例2: ExecuteResult
/// <summary>
/// ExecuteResult
/// </summary>
/// <param name="context"></param>
public override void ExecuteResult(ControllerContext context)
{
context.HttpContext.Response.Clear();
context.HttpContext.Response.ContentType = "application/pdf";
if (Download)
context.HttpContext.Response.AddHeader("content-disposition", "attachment; filename=" + FileName);
Html = RenderRazorViewToString(context);
Format(context.HttpContext);
using (var document = new Document(Settings.PageSize, Settings.Margin.Left, Settings.Margin.Right, Settings.Margin.Top, Settings.Margin.Bottom))
{
var memoryStream = new MemoryStream();
TextReader textReader = new StringReader(Html);
var pdfWriter = PdfWriter.GetInstance(document, memoryStream);
var htmlPipelineContext = new HtmlPipelineContext(null);
var cssResolver = XMLWorkerHelper.GetInstance().GetDefaultCssResolver(false);
document.Open();
FontFactory.RegisterDirectories();
htmlPipelineContext.SetTagFactory(Tags.GetHtmlTagProcessorFactory());
foreach (var styleSheet in StyleSheets)
{
cssResolver.AddCssFile(context.HttpContext.Server.MapPath(styleSheet), true);
}
var pipeline = new CssResolverPipeline(cssResolver, new HtmlPipeline(htmlPipelineContext, new PdfWriterPipeline(document, pdfWriter)));
var worker = new XMLWorker(pipeline, true);
var xmlParse = new XMLParser(true, worker);
xmlParse.Parse(textReader);
xmlParse.Flush();
document.Close();
document.Dispose();
context.HttpContext.Response.BinaryWrite(memoryStream.ToArray());
}
context.HttpContext.Response.End();
context.HttpContext.Response.Flush();
}