private void button1_Click(object sender, EventArgs e)
{
var options = new PdfExportingOptions();
var document = new PdfDocument();
document.PageSettings.Orientation = PdfPageOrientation.Landscape;
var page = document.Pages.Add();
var PDFGrid = sfDataGrid1.ExportToPdfGrid(sfDataGrid1.View, options);
PDFGrid.Columns[0].Width = 400;
PDFGrid.Draw(page, new PointF());
document.Save("Sample.pdf");
} |
Dim options As New PdfExportingOptions() options.AutoColumnWidth = True options.ExportTableSummary = True options.ExportStackedHeaders = True options.ExportUnboundRows = True Dim document = new PdfDocument() document.PageSettings.Orientation = PdfPageOrientation.Landscape options.FitAllColumnsInOnePage = True Dim page = document.Pages.Add() Dim PDFGrid = dgvStock.ExportToPdfGrid(dgvStock.View, options) Dim format = New PdfGridLayoutFormat() With {.Layout = PdfLayoutType.Paginate, .Break = PdfLayoutBreakType.FitPage} PDFGrid.Draw(page, New PointF(), format) document.Save("Item Stock Report.Pdf") Dim sfd As SaveFileDialog = New SaveFileDialog With {.FilterIndex = 1, .Filter = "PDF Files(*.PDF)|*.pdf|PDF Files(*.xlsx)|*.xlsx", .FileName = "" & Me.Title & ""} If sfd.ShowDialog() = System.Windows.Forms.DialogResult.OK Then Using stream As Stream = sfd.OpenFile() document.Save(stream) End Using 'Message box confirmation to view the created spreadsheet. If MessageBox.Show("Do you want to view the Pdf File?", "PDF has been created", MessageBoxButtons.OKCancel) = System.Windows.Forms.DialogResult.OK Then 'Launching the Excel file using the default Application.[MS Excel Or Free ExcelViewer] System.Diagnostics.Process.Start(sfd.FileName) End If End If |