private void ExportPDFClick(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = String.Format("{0} (*{1})|*{1}", "PDF FIles", ".pdf"); if (sfd.ShowDialog() == DialogResult.OK) { ExportToPDF exporter = new ExportToPDF(this.radGridView1); exporter.FileExtension = "pdf"; exporter.HiddenColumnOption = Telerik.WinControls.UI.Export.HiddenOption.DoNotExport; exporter.ExportVisualSettings = true; exporter.PageTitle = "My Page Title"; exporter.SummariesExportOption = SummariesOption.DoNotExport; exporter.FitToPageWidth = true; exporter.Scale = 1.2f; exporter.TableBorderThickness = 1; exporter.PdfExportSettings.PageHeight = 210; exporter.PdfExportSettings.PageWidth = 297; exporter.PdfExportSettings.Author = "Telerik"; exporter.HTMLCellFormatting += new Telerik.WinControls.UI.Export.HTML.HTMLCellFormattingEventHandler (exporter_HTMLCellFormatting); exporter.RunExport(sfd.FileName); MessageBox.Show("Export completed"); } }
private void RunExportToPDF(string fileName, ref bool openExportFile) { ExportToPDF pdfExporter = new ExportToPDF(this.radGridView1); pdfExporter.PdfExportSettings.Title = "My PDF Title"; pdfExporter.PdfExportSettings.PageWidth = 297; pdfExporter.PdfExportSettings.PageHeight = 210; pdfExporter.FitToPageWidth = true; pdfExporter.HTMLCellFormatting += pdfExporter_HTMLCellFormatting; switch (this.radComboBoxSummaries.SelectedIndex) { case 0: pdfExporter.SummariesExportOption = SummariesOption.ExportAll; break; case 1: pdfExporter.SummariesExportOption = SummariesOption.ExportOnlyTop; break; case 2: pdfExporter.SummariesExportOption = SummariesOption.ExportOnlyBottom; break; case 3: pdfExporter.SummariesExportOption = SummariesOption.DoNotExport; break; } //set export settings pdfExporter.ExportVisualSettings = true; pdfExporter.ExportHierarchy = true; pdfExporter.HiddenColumnOption = HiddenOption.DoNotExport; try { this.Cursor = Cursors.WaitCursor; pdfExporter.RunExport(fileName); RadMessageBox.SetThemeName(this.radGridView1.ThemeName); DialogResult dr = RadMessageBox.Show("The data in the grid was exported successfully. Do you want to open the file?", "Export to PDF", MessageBoxButtons.YesNo, RadMessageIcon.Question); if (dr == DialogResult.Yes) { openExportFile = true; } } catch (IOException ex) { RadMessageBox.SetThemeName(this.radGridView1.ThemeName); RadMessageBox.Show(this, ex.Message, "I/O Error", MessageBoxButtons.OK, RadMessageIcon.Error); } finally { this.Cursor = Cursors.Default; } }
public static void RunExportToPDF(string fileName, RadGridView radGridView) { ExportToPDF pdfExporter = new ExportToPDF(radGridView); pdfExporter.PdfExportSettings.Title = "My PDF Title"; pdfExporter.PdfExportSettings.PageWidth = 297; pdfExporter.PdfExportSettings.PageHeight = 210; pdfExporter.FitToPageWidth = true; pdfExporter.HTMLCellFormatting += pdfExporter_HTMLCellFormatting; pdfExporter.SummariesExportOption = SummariesOption.ExportAll; //set export settings //pdfExporter.ExportVisualSettings = this.radCheckBoxExportVisual.IsChecked; //pdfExporter.ExportHierarchy = this.radCheckBoxExportHierarchy.IsChecked; pdfExporter.HiddenColumnOption = HiddenOption.DoNotExport; try { //this.Cursor = Cursors.WaitCursor; pdfExporter.RunExport(fileName); RadMessageBox.SetThemeName(radGridView.ThemeName); DialogResult dr = RadMessageBox.Show("The data in the grid was exported successfully. Do you want to open the file?", "Export to PDF", MessageBoxButtons.YesNo, RadMessageIcon.Question); if (dr == DialogResult.Yes) { try { System.Diagnostics.Process.Start(fileName); } catch (Exception ex) { string message = String.Format("The file cannot be opened on your system.\nError message: {0}", ex.Message); RadMessageBox.Show(message, "Open File", MessageBoxButtons.OK, RadMessageIcon.Error); } } } catch (IOException ex) { RadMessageBox.SetThemeName(radGridView.ThemeName); //RadMessageBox.Show(this, ex.Message, "I/O Error", MessageBoxButtons.OK, RadMessageIcon.Error); System.Windows.Forms.MessageBox.Show(ex.Message, "ERR", MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { //this.Cursor = Cursors.Default; } }