public void SaveGridToPdf()
        {
            var dataTable = Session["datatableForGrid"] as DataTable;

            if (dataTable == null || dataTable.Rows.Count == 0)
            {
                return;
            }

            var pdfExporter = DataTableToPdfExporter.CreateInstance();
            var pdfStream   = pdfExporter.DataTableExportToMemory(dataTable, "Result query");

            SaveGridToFile(pdfStream, "application/pdf", "Result.pdf");
        }
Пример #2
0
        public static void SavePDF(DataTable table, string title)
        {
            // Configure save file dialog box
            Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
            dlg.FileName   = "ResultQuery";           // Default file name
            dlg.DefaultExt = ".pdf";                  // Default file extension
            dlg.Filter     = "Text documents |*.pdf"; // Filter files by extension

            // Show save file dialog box
            bool?result = dlg.ShowDialog();

            // Process save file dialog box results
            if (result == true)
            {
                // Save document
                string filename = dlg.FileName;
                var    file     = DataTableToPdfExporter.CreateInstance();
                file.DataTableExport(table, filename, title);
            }
        }