private static void OnExecuteExportToPdf(object sender, ExecutedRoutedEventArgs args) { var dataGrid = args.Source as SfDataGrid; var optionsettings = args.Parameter as PDFExportingOptionsWrapper; if (dataGrid == null || optionsettings == null) { return; } try { var options = new PdfExportingOptions(); options.AutoColumnWidth = optionsettings.IsAutoColumnWidth ? true : false; options.AutoRowHeight = optionsettings.IsAutoRowHeight ? true : false; options.ExportGroups = optionsettings.CanExportGroup ? true : false; options.ExportGroupSummary = optionsettings.CanExportGroupSummary ? true : false; options.ExportTableSummary = optionsettings.CanExportTableSummary ? true : false; options.RepeatHeaders = optionsettings.CanRepeatHeader ? true : false; options.FitAllColumnsInOnePage = optionsettings.IsFitAllColumns ? true : false; options.CellsExportingEventHandler = GridCellPdfExportingEventhandler; options.ExportingEventHandler = GridPdfExportingEventhandler; options.PageHeaderFooterEventHandler = PdfHeaderFooterEventHandler; var document = dataGrid.ExportToPdf(dataGrid.SelectedItems, options); SaveFile(document); } catch (Exception) { } }
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { var options = new PdfExportingOptions(); if (!(bool)values[0]) { options.AutoColumnWidth = false; } if (!(bool)values[1]) { options.AutoRowHeight = false; } if (!(bool)values[2]) { options.ExportGroups = false; } if (!(bool)values[3]) { options.ExportGroupSummary = false; } if (!(bool)values[4]) { options.ExportTableSummary = false; } if (!(bool)values[5]) { options.RepeatHeaders = false; } if ((bool)values[6]) { options.FitAllColumnsInOnePage = true; } return(options); }
private void LoadDocumentToPdfViewer() { //Create Memory Stream to save pdfdocument. MemoryStream pdfstream = new MemoryStream(); //Intialize the PdfDocument PdfDocument pdfDoc = new PdfDocument(); PdfExportingOptions options = new PdfExportingOptions(); options.FitAllColumnsInOnePage = true; ////Convert grid into PDF document pdfDoc = dataGrid.ExportToPdf(options); //Save the PDF file pdfDoc.Save(pdfstream); //Load the pdfstream to pdfDocumentView pdfDocumentView1.Load(pdfstream); lblTotalPageCount.Text = pdfDocumentView1.PageCount.ToString(); EnablePagination(); pageTimer.Tick += pageTimer_Tick; pageTimer.Start(); }
/// <summary> /// Method for export the selected records in SfDataGrid to PDF /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void OnPdfExportSelectedItems(object sender, RoutedEventArgs e) { cellstyle = new PdfGridCellStyle(); cellstyle.StringFormat = new PdfStringFormat() { Alignment = PdfTextAlignment.Right }; cellstyle.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 9f, PdfFontStyle.Regular); var options = new PdfExportingOptions() { AutoColumnWidth = (bool)this.ColumnWidth.IsChecked, AutoRowHeight = (bool)this.RowHeight.IsChecked, ExportGroups = (bool)this.ExportGroup.IsChecked, ExportGroupSummary = (bool)this.ExportGroupSummary.IsChecked, ExportTableSummary = (bool)this.ExportTableSummary.IsChecked, RepeatHeaders = (bool)this.RepeatHeader.IsChecked, FitAllColumnsInOnePage = (bool)this.FitAllColumns.IsChecked, ExportingEventHandler = GridPdfExportingEventhandler, CellsExportingEventHandler = GridCellPdfExportingEventhandler, PageHeaderFooterEventHandler = PdfHeaderFooterEventHandler }; var pdfDocument = this.sfGrid.ExportToPdf(this.sfGrid.SelectedItems, options); pdfDocument.PageSettings.Margins.Top = -34f; pdfDocument.PageSettings.Margins.Bottom = -30f; var savePicker = new FileSavePicker { SuggestedStartLocation = PickerLocationId.Desktop, SuggestedFileName = "Sample" }; savePicker.FileTypeChoices.Add("Pdf Files(.pdf)", new List <string>() { ".pdf" }); var storageFile = await savePicker.PickSaveFileAsync(); if (storageFile != null) { await pdfDocument.SaveAsync(storageFile); var msgDialog = new MessageDialog("Do you want to view the Document?", "File has been created successfully."); var yesCmd = new UICommand("Yes"); var noCmd = new UICommand("No"); msgDialog.Commands.Add(yesCmd); msgDialog.Commands.Add(noCmd); var cmd = await msgDialog.ShowAsync(); if (cmd == yesCmd) { // Launch the saved file bool success = await Windows.System.Launcher.LaunchFileAsync(storageFile); } } }
private void Export_Click(object sender, RoutedEventArgs e) { PdfExportingOptions options = new PdfExportingOptions(); options.PageHeaderFooterEventHandler = PdfHeaderFooterEventHandler; var document = dataGrid.ExportToPdf(options); document.Save("Sample3.pdf"); }
private void PDF_Exporting(object sender, EventArgs e) { PdfExportingOptions options = new PdfExportingOptions(); options.ExportStackedHeaders = true; options.CellExporting += options_CellExporting; var document = sfDataGrid1.ExportToPdf(options); document.Save("Sample.pdf"); }
private void button_ExportPdf_Click(object sender, EventArgs e) { (string title, string _) = GenerateTitle($"Bel Report", "x"); saveFileDialog1.Filter = "Pdf files|*.pdf|All files|*.*"; string filePath = ShowSaveDialog("Export Pdf"); if (string.IsNullOrEmpty(filePath)) { return; } PdfExportingOptions options = new PdfExportingOptions(); //options.AutoColumnWidth = true; options.AutoRowHeight = true; options.ExcludeColumns = new List <string> { nameof(ReportModel.Emphasis), nameof(ReportModel.VolumeId) }; foreach (var col in sfDataGrid1.Columns.Where(x => !x.Visible)) { options.ExcludeColumns.Add(col.HeaderText); } options.RepeatHeaders = true; options.FitAllColumnsInOnePage = true; options.AutoColumnWidth = true; options.ExportGroups = true; options.ExportDetailsView = true; var document = new PdfDocument(); document.PageSettings.Orientation = PdfPageOrientation.Landscape; var page = document.Pages.Add(); var PDFGrid = sfDataGrid1.ExportToPdfGrid(sfDataGrid1.View, options); var format = new PdfGridLayoutFormat() { Layout = PdfLayoutType.Paginate, Break = PdfLayoutBreakType.FitPage }; PDFGrid.Draw(page, new PointF(), format); //Syncfusion.Pdf.PdfDocument document = sfDataGrid1.ExportToPdf(options); //document.PageSettings.Orientation = Syncfusion.Pdf.PdfPageOrientation.Landscape; document.Save(filePath); //GenerateDataForExport(); //var exporter = m_ExporterProvider.Provide("Pdf"); //string exportData = exporter.Export(title, ExportColNames, ExportData); //File.WriteAllText(filePath, exportData); }
private void BtnPdfServices_OnClick(object sender, RoutedEventArgs e) { var options = new PdfExportingOptions() { AutoColumnWidth = true, AutoRowHeight = true, ExcludeColumns = new List <string>() { "Id", "btn" }, ExportDetailsView = true }; var document = ServiceDataGrid.ExportToPdf(options); GeneratePDF(document); }
private async void OnPdfExportDataGrid(object sender, RoutedEventArgs e) { cellstyle = new PdfGridCellStyle(); cellstyle.StringFormat = new PdfStringFormat() { Alignment = PdfTextAlignment.Right }; cellstyle.Font = new PdfStandardFont(PdfFontFamily.Helvetica, 9f, PdfFontStyle.Regular); cellstyle.Borders.All = new PdfPen(PdfBrushes.DarkGray, 0.2f); var options = new PdfExportingOptions() { AutoColumnWidth = (bool)this.ColumnWidth.IsChecked, AutoRowHeight = (bool)this.RowHeight.IsChecked, ExportGroups = (bool)this.ExportGroup.IsChecked, ExportGroupSummary = (bool)this.ExportGroupSummary.IsChecked, ExportTableSummary = (bool)this.ExportTableSummary.IsChecked, RepeatHeaders = (bool)this.RepeatHeader.IsChecked, FitAllColumnsInOnePage = (bool)this.FitAllColumns.IsChecked, ExportingEventHandler = GridPdfExportingEventhandler, CellsExportingEventHandler = GridCellPdfExportingEventhandler, PageHeaderFooterEventHandler = PdfHeaderFooterEventHandler }; var pdfDocument = this.sfDataGrid.ExportToPdf(this.sfDataGrid.SelectedItems, options); pdfDocument.PageSettings.Margins.Top = -34f; pdfDocument.PageSettings.Margins.Bottom = -30f; var savePicker = new FileSavePicker { SuggestedStartLocation = PickerLocationId.Desktop, SuggestedFileName = "Sample" }; savePicker.FileTypeChoices.Add("Pdf Files(.pdf)", new List<string>() { ".pdf" }); var storageFile = await savePicker.PickSaveFileAsync(); if (storageFile != null) { await pdfDocument.SaveAsync(storageFile); var msgDialog = new MessageDialog("Do you want to view the Document?", "File has been created successfully."); var yesCmd = new UICommand("Yes"); var noCmd = new UICommand("No"); msgDialog.Commands.Add(yesCmd); msgDialog.Commands.Add(noCmd); var cmd = await msgDialog.ShowAsync(); if (cmd == yesCmd) { // Launch the saved file bool success = await Windows.System.Launcher.LaunchFileAsync(storageFile); } } }
private void toolStripButton3_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; PdfExportingOptions options = new PdfExportingOptions(); var document = new PdfDocument(); document.PageSettings.Orientation = PdfPageOrientation.Landscape; var page = document.Pages.Add(); options.AutoColumnWidth = true; options.AutoRowHeight = true; options.RepeatHeaders = true; options.ExportGroups = true; options.ExportStackedHeaders = true; options.FitAllColumnsInOnePage = true; foreach (var c in SelectedGrid.Columns) { if (c.Width == 0) { options.ExcludeColumns.Add(c.MappingName); } } var PDFGrid = SelectedGrid.ExportToPdfGrid(SelectedGrid.View, options); var format = new PdfGridLayoutFormat() { Layout = PdfLayoutType.Paginate, Break = PdfLayoutBreakType.FitPage }; PDFGrid.Draw(page, new PointF(), format); SaveFileDialog sfd = new SaveFileDialog { Filter = "Pdf Image|*.pdf|Ficheiro pdf|*.pdf", Title = "Guardar ficheiro pdf" }; if (sfd.ShowDialog() == DialogResult.OK) { document.Save(sfd.FileName); Process.Start(sfd.FileName); } Cursor.Current = Cursors.Default; }
private void ExportPDF_Click(object sender, RoutedEventArgs e) { var options = new PdfExportingOptions(); options.FitAllColumnsInOnePage = true; options.ExcludeColumns.Add("cod_ant"); options.ExcludeColumns.Add("nom_ter"); options.ExcludeColumns.Add("nom_mer"); options.ExcludeColumns.Add("nom_tip"); var document = dataGridConsulta.ExportToPdf(options); document.PageSettings.Orientation = PdfPageOrientation.Landscape; //var document = new PdfDocument(); //document.PageSettings.Orientation = PdfPageOrientation.Landscape; //var page = document.Pages.Add(); //var PDFGrid = dataGridConsulta.ExportToPdfGrid(dataGridConsulta.View, options); //PDFGrid.Draw(page, new PointF(), format); SaveFileDialog sfd = new SaveFileDialog { Filter = "PDF Files(*.pdf)|*.pdf" }; if (sfd.ShowDialog() == true) { using (Stream stream = sfd.OpenFile()) { document.Save(stream); } //Message box confirmation to view the created Pdf file. if (MessageBox.Show("Do you want to view the Pdf file?", "Pdf file has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { //Launching the Pdf file using the default Application. System.Diagnostics.Process.Start(sfd.FileName); } } }
void OnExportPDFButtonClick(object sender, RoutedEventArgs e) { var dataGrid = Grid; if (dataGrid == null) { return; } try { var options = new PdfExportingOptions(); options.FitAllColumnsInOnePage = true; var document = dataGrid.ExportToPdf(options); SaveFileDialog sfd = new SaveFileDialog { Filter = "PDF Files(*.pdf)|*.pdf" }; if (sfd.ShowDialog() == true) { using (Stream stream = sfd.OpenFile()) { document.Save(stream); } //Message box confirmation to view the created Pdf file. if (MessageBox.Show("Do you want to view the Pdf file?", "Pdf file has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { //Launching the Pdf file using the default Application. System.Diagnostics.Process.Start(sfd.FileName); } } } catch (Exception) { } }
private static void OnExecuteExportToPdf(object sender, ExecutedRoutedEventArgs args) { var dataGrid = args.Source as SfDataGrid; var optionsettings = args.Parameter as PDFExportingOptionsWrapper; if (dataGrid == null || optionsettings == null) { return; } try { var options = new PdfExportingOptions(); options.CellsExportingEventHandler = GridCellPdfExportingEventhandler; options.ExportingEventHandler = GridPdfExportingEventhandler; options.PageHeaderFooterEventHandler = PdfHeaderFooterEventHandler; var document = dataGrid.ExportToPdf(dataGrid.SelectedItems, options); SaveFile(document); } catch (Exception) { } }
private void _view_OnButtonExportPDFClick(object sender, ToolStripItemClickedEventArgs e) { var options = new PdfExportingOptions(); var saveFileDialog = new SaveFileDialog(); saveFileDialog.Title = "Export to PDF"; saveFileDialog.Filter = "PDF Files|*.pdf"; saveFileDialog.FileName = $"export_barang_{DateTime.Now.ToString("ddMMyyyy")}_{DateTime.Now.ToString("HHmmss")}"; if (saveFileDialog.ShowDialog() == DialogResult.OK) { var document = _view.ListDataGrid.ExportToPdf(options); document.Save(saveFileDialog.FileName); if (Messages.Confirm("Apakah anda ingin membuka filenya sekarang?", "Export to PDF")) { var proc = new Process(); proc.StartInfo.FileName = saveFileDialog.FileName; proc.Start(); } } }
/// <summary> /// Exports the Selected rows of SfDataGrid to PDF. /// </summary> private void ExportSelectedItemToPdf(object sender, EventArgs e) { PdfExportingOptions exportingOptions = new PdfExportingOptions(); exportingOptions.ExportDetailsView = true; exportingOptions.ExportAllDetails = true; exportingOptions.CellExporting += OnSelectedItemsCellExporting; if (shouldCustomizeSelectedItems.Checked) { exportingOptions.Exporting += CustomizeSelectedItemsExporting; } else { exportingOptions.Exporting += OnExporting; } var document = sfDataGrid1.ExportToPdf(sfDataGrid1.SelectedItems, exportingOptions); SaveFileDialog sfd = new SaveFileDialog { Filter = "PDF Files(*.pdf)|*.pdf", FileName = "Sample" }; if (sfd.ShowDialog() == DialogResult.OK) { using (Stream stream = sfd.OpenFile()) { document.Save(stream); } //Message box confirmation to view the created Pdf file. if (MessageBox.Show("Do you want to view the created Pdf file?", "Pdf has been created", MessageBoxButtons.OKCancel) == DialogResult.OK) { //Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer] Open(sfd.FileName); } } }
private void ExporteExecute(object obj) { var dataGrid = obj as SfDataGrid; if (dataGrid == null) { return; } try { if ((dataGrid.DataContext as ViewModel).ComboBoxExportSelectedItem.ToString() == "Excel") { ExcelEngine excelEngine = dataGrid.ExportCollectionToExcel(dataGrid.View, ExcelVersion.Excel2007, exportingHandler, cellsExportingHandler, true); IWorkbook workBook = excelEngine.Excel.Workbooks[0]; SaveFileDialog sfd = new SaveFileDialog { FilterIndex = 1, Filter = "Excel 2007 to 2010 Files(*.xlsx)|*.xlsx|Excel 97 to 2003 Files(*.xls)|*.xls" }; if (sfd.ShowDialog() == true) { using (Stream stream = sfd.OpenFile()) { if (sfd.FilterIndex == 1) { workBook.Version = ExcelVersion.Excel2010; } else { workBook.Version = ExcelVersion.Excel97to2003; } workBook.SaveAs(stream); } //Message box confirmation to view the created spreadsheet. if (MessageBox.Show("Do you want to view the workbook?", "Workbook has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { //Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer] Open(sfd.FileName); } } } else { var options = new PdfExportingOptions(); options.ExportAllPages = true; var document = dataGrid.ExportToPdf(options); SaveFileDialog sfd = new SaveFileDialog { Filter = "PDF Files(*.pdf)|*.pdf", FileName = "document1" }; if (sfd.ShowDialog() == true) { using (Stream stream = sfd.OpenFile()) { document.Save(stream); } //Message box confirmation to view the created Pdf file. if (MessageBox.Show("Do you want to view the Pdf file?", "Pdf file has been created", MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) { //Launching the Pdf file using the default Application. System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo(sfd.FileName); info.UseShellExecute = true; System.Diagnostics.Process.Start(info); } } } } catch (Exception) { } }
public void ExportToPdf(SfDataGrid dataGrid) { if (dataGrid == null) { return; } try { var options = new PdfExportingOptions(); options.CellsExportingEventHandler = GridCellPdfExportingEventhandler; options.ExportingEventHandler = GridPdfExportingEventhandler; options.PageHeaderFooterEventHandler = PdfHeaderFooterEventHandler; options.ExportStackedHeaders = true; var document = dataGrid.ExportToPdf(options); MemoryStream stream = new MemoryStream(); document.Save(stream); PdfViewerControl pdfViewer = new PdfViewerControl(); pdfViewer.Load(stream); Window window = new Window(); window.Content = pdfViewer; window.Show(); //var document = new PdfDocument(); //document.PageSettings.Orientation = PdfPageOrientation.Landscape; //document.PageSettings.SetMargins(20); //var page = document.Pages.Add(); //var pdfGrid = dataGrid.ExportToPdfGrid(dataGrid.View, options); //var format = new PdfGridLayoutFormat() //{ // Layout = PdfLayoutType.Paginate, // Break = PdfLayoutBreakType.FitPage //}; //pdfGrid.Draw(page, new PointF(), format); //SaveFileDialog sfd = new SaveFileDialog //{ // Filter = "PDF Files(*.pdf)|*.pdf" //}; //if (sfd.ShowDialog() == true) //{ // using (Stream stream = sfd.OpenFile()) // { // document.Save(stream); // } // //Message box confirmation to view the created Pdf file. // if (MessageBox.Show("Do you want to view the Pdf file?", "Pdf file has been created", // MessageBoxButton.YesNo, MessageBoxImage.Information) == MessageBoxResult.Yes) // { // //Launching the Pdf file using the default Application. // System.Diagnostics.Process.Start(sfd.FileName); // } //} } catch (Exception) { } }