2017-04-08 77 views
0

我有用於打印使用iTextSharp.dll(PDF產生LIB)使用如何打印ajaxtoolkit餅圖(pdf格式)?

命名空間正常代碼扇形圖:

using iTextSharp.text; 
using iTextSharp.text.pdf; 
using System.IO; 
using System.Web.UI.DataVisualization.Charting; 

代碼:對AJAX

Document pdfDoc = new Document(PageSize.A4, 10f, 10f, 10f, 0f); 
    PdfWriter.GetInstance(pdfDoc, Response.OutputStream); 
    pdfDoc.Open(); 
    using (MemoryStream stream = new MemoryStream()) 
    { 
     PieChart1.SaveImage(stream, ChartImageFormat.Png); //error line 
     iTextSharp.text.Image chartImage = iTextSharp.text.Image.GetInstance(stream.GetBuffer()); 
     chartImage.ScalePercent(75f); 
     pdfDoc.Add(chartImage); 
     pdfDoc.Close(); 

     Response.ContentType = "application/pdf"; 
     Response.AddHeader("content-disposition", "attachment;filename=Chart.pdf"); 
     Response.Cache.SetCacheability(HttpCacheability.NoCache); 
     Response.Write(pdfDoc); 
     Response.End(); 
    } 

但這代碼這麼想的工作餅圖,它顯示錯誤:

Error 1 'AjaxControlToolkit.PieChart' does not contain a definition for 'SaveImage' and no extension method 'SaveImage' accepting a first argument of type 'AjaxControlToolkit.PieChart' could be found (are you missing a using directive or an assembly reference?)

也我有沒有其他的方式,如從JavaScript打印餅圖的div? 或任何其他代碼示例/參考?

回答

-1

如果你想從JavaScript執行操作。我建議你使用Highcharts,它最適合所有類型的圖表,並且它可以讓內置打印和下載爲圖像或PDF。 http://www.highcharts.com/demo/pie-basic 檢查此鏈接並演示它是用戶友好和重量輕。