Exporting the data SfDataGrid to Pdf

Hello!


When exporting the SfDatagrid data to Pdf, the below listed errors:

1.pdfviewer is ambiguous in the namespace 'Syncfusion.Windows.Forms.Pdfviewer'
2. pdfviewer is not declared.
3. PrinterSettings is not a member of 'Syncfusion.Windows.Forms.PdfViewer'.
4. pdfviewerPrintOrientatio is ambiguous in the namespace 'Syncfusion.Windows.Forms.Pdfviewer'





6 Replies 1 reply marked as answer

MA Mohanram Anbukkarasu Syncfusion Team October 2, 2020 06:19 AM UTC

Hi Boopathi, 

Thanks for contacting Syncfusion products.  

We are little unclear with the reported issues. There is no need to use PdfViewer just for exporting the SfDataGrid to Pdf. We suspect that you are using PdfViewerControl to view and print PDF file exported from SfDataGrid. You can find the assembly references from using PdfViewControl from the following link. 


Please revert to us with the following details.  
  1. Complete code snippets you have used in your application for exporting the SfDataGrid to Pdf.
  2. Syncfusion product version you are using in your application.
 
These details will help for us to validate and find the exact cause for the issue and to provide a prompt solution at earlier. 

Regards, 
Mohanram A. 



BO Boopathi October 2, 2020 11:30 AM UTC

Hi Mohanram,

Thanks for you support.

One more request how to change the particular column size while exporting to pdf.


MA Mohanram Anbukkarasu Syncfusion Team October 5, 2020 04:49 PM UTC

Hi Boopathi,  

Thanks for the update.  

We are currently working on this query. We will update with further details on 6th October 2020. We appreciate your patience until then.  

Regards, 
Mohanram A. 



MA Mohanram Anbukkarasu Syncfusion Team October 6, 2020 10:16 AM UTC

Hi Boopathi, 

Thanks for your patience.  

You can change the width of a particular column while exporting to pdf as shown in the following code example. 

Code example :  

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"); 
} 


Please let us know if you require further assistance from us.  

Regards, 
Mohanram A. 


Marked as answer

BO Boopathi October 6, 2020 01:10 PM UTC

Hi Manoharam,

Thanks for your support.

I have one more query. That's I set page orientation as Landscape. But it's exporting both orientations.

Please find the below code for your reference.
Code:
            Dim options As New PdfExportingOptions()
            options.AutoColumnWidth = True
            options.ExportTableSummary = True
            options.ExportStackedHeaders = True
            options.ExportUnboundRows = True
            Dim document = dgvStock.ExportToPdf(options)
            document.PageSettings.Orientation = PdfPageOrientation.Landscape
            options.FitAllColumnsInOnePage = True
            document.Save("Item Stock Report.Pdf")

            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)


            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




VS Vijayarasan Sivanandham Syncfusion Team October 7, 2020 03:23 PM UTC

Hi Boopathi,

Thanks for the update.

In your provided code snippet your set the document as for SfDataGrid.ExportToPDF. Please refer the below Screen shot,


Your requirement can be achieved by define the Document as PDFDocument to resolve the reported issue. Please refer the below code snippet, 
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 
 
We hope this helps. Please let us know, if you require further assistance on this.

Regards,
Vijayarasan S 


Loader.
Up arrow icon