ASP.NET Web Forms - How to export ASPxPivotGrid and bound WebChartControl to the same print document
This example demonstrates how to combine several ASP.NET controls in one exported document. This project shows how to apply this solution to ASPxPivotGrid and WebChartControl, but it is also applicable to other components that implement the IPrintable and IBasePrintable interfaces.
Note
This example uses the Printing.Core library. Make sure that you include it in your project.
- Create a PrintableComponentLinkBase object for each exported component.
- Specify the PrintableComponentLinkBase.Component property.
- Create a CompositeLinkBase object to combine several printing links.
- Add
PrintableComponentLinkBaseobjects to the CompositeLinkBase.Links collection. - Call the CompositeLinkBase.ExportTo[FORMAT] method to export the document.
PrintingSystemBase ps = new PrintingSystemBase();
ps.ExportOptions.Pdf.DocumentOptions.Author = "Test";
PrintableComponentLinkBase link1 = new PrintableComponentLinkBase(ps);
link1.Component = ASPxPivotGridExporter1;
PrintableComponentLinkBase link2 = new PrintableComponentLinkBase(ps);
WebChartControl1.DataBind();
link2.Component = ((IChartContainer)WebChartControl1).Chart;
CompositeLinkBase compositeLink = new CompositeLinkBase(ps);
compositeLink.Links.AddRange(new object[] { link1, link2 });
using (MemoryStream stream = new MemoryStream()) {
compositeLink.ExportToPdf(stream);
Response.Clear();
Response.Buffer = false;
Response.AppendHeader("Content-Type", "application/pdf");
Response.AppendHeader("Content-Transfer-Encoding", "binary");
Response.AppendHeader("Content-Disposition", "attachment; filename=test.pdf");
Response.BinaryWrite(stream.ToArray());
Response.End();
}
ps.Dispose();- Default.aspx (VB: Default.aspx)
- Default.aspx.cs (VB: Default.aspx.vb)
- How to export several controls to different XLSX worksheets
- How to export ASPxGridView and WebChartControl to the same print document
- Grid View for Web Forms - How to export multiple grids into a single print document
(you will be redirected to DevExpress.com to submit your response)