private MemoryStream ConvertWebChartChartToImage(WebChartControl chart)
{
using (var pcl = new PrintableComponentLink(new PrintingSystem())
{
PageHeaderFooter = new PageHeaderFooter(new PageHeaderArea(new string[] { "A", "Header" },
SystemFonts.DialogFont, BrickAlignment.Center),
new PageFooterArea(new string[] { "B" },
SystemFonts.DialogFont, BrickAlignment.Center)),
Component = ((IChartContainer)chart).Chart,
Landscape = true
})
{
((Chart)pcl.Component).OptionsPrint.SizeMode = DevExpress.XtraCharts.Printing.PrintSizeMode.Stret ch;
TransDistributionWCh.Legend.AlignmentHorizontal = LegendAlignmentHorizontal.Right;
pcl.CreateDocument();
var stream = new MemoryStream();
pcl.PrintingSystem.ExportToPdf(stream);
return stream;
}
}
private void ConvertHTMLStringToPDF()
{
using (var stream = new MemoryStream())
{
var listChartControl = new List<WebChartControl>(new List<WebChartControl>
{
SuccTransDistributionWCh,
AmountPerDayWCh,
TransPerDayWCh,
AmountPerTransPerDayWCh,
ActiveTerminalPerDayWCh,
TransNoWCh,
TransAmountWCh,
TransNoAmountWCh
});
foreach (var item in listChartControl)
{
var temp = ConvertWebChartChartToImage(item);
stream.Write(temp.ToArray(), 0, temp.ToArray().Length);
}
HttpContext.Current.Response.ContentType = "application/pdf";
HttpContext.Current.Response.AddHeader("Accept-Header", stream.Length.ToString(CultureInfo.InvariantCulture));
HttpContext.Current.Response.AddHeader("Content-Disposition", ("Attachment") + "; filename=chart.pdf");
HttpContext.Current.Response.AddHeader("Content-Length", stream.Length.ToString(CultureInfo.InvariantCulture));
HttpContext.Current.Response.ContentEncoding = Encoding.Default;
HttpContext.Current.Response.BinaryWrite(stream.ToArray());
}
HttpContext.Current.Response.End();}
我正在使用 web control chart dev express,需要将 web control chart 转换为 pdf 我的问题:如何将数据添加到内存流?此代码显示最后一个 web 图表我建议零号错误 stream.Write(temp.ToArray(), 0, temp.ToArray().Length); 搜索谷歌和这个网站不幸的是问题没有解决