private void ExportPDFButton_Click(object sender, EventArgs e) { try { string path = Application.StartupPath + "\\ChartExport.pdf"; NPdfImageFormat fmt = new NPdfImageFormat(); fmt.CompressContentStream = true; nChartControl1.ImageExporter.SaveToFile(path, fmt); Process.Start(path); } catch (Exception x) { MessageBox.Show(x.Message); } }
/// <summary> /// Default constructor. /// </summary> public NPdfExportRenderPage() { DrawingView = new NDrawingView(); DrawingView.ViewLayout = CanvasLayout.Normal; string format = HttpContext.Current.Request.QueryString["format"]; if (format == "pdf") { // Create a pdf image format NPdfImageFormat imageFormat = new NPdfImageFormat(); imageFormat.PageSize = new NSizeF(GetSizeInPoints("PageWidth"), GetSizeInPoints("PageHeight")); imageFormat.PageMargins = new NMarginsF(GetSizeInPoints("MarginsLeft"), GetSizeInPoints("MarginsTop"), GetSizeInPoints("MarginsRight"), GetSizeInPoints("MarginsBottom")); imageFormat.ZoomPercent = GetFloat("ZoomPercent"); if (GetBoolean("FitToPage")) { imageFormat.Layout = PagedLayout.FitToPages; } // Override the default response NImageResponse imageResponse = new NImageResponse(); imageResponse.ImageFormat = imageFormat; imageResponse.StreamImageToBrowser = true; DrawingView.ServerSettings.BrowserResponseSettings.DefaultResponse = imageResponse; } // init document NDrawingDocument document = this.DrawingView.Document; document.BeginInit(); CreateScene(document); document.EndInit(); this.DrawingView.SizeToContent(); }