ExportToPdf not allowing landscape orientation

Have code using ExportToPdf to export my sfDatagrid.  It refuses to orient in landscape mode.  If I use PDFDocument, it will however the only way to add header text is to use the ExportToPdf.  Any advice?  I am on the la

Here is my code:

    Try

        If dtBenRickPrint.Rows.Count > 0 Then

            Try

                Dim options As New PdfExportingOptions()

                AddHandler options.HeaderFooterExporting, AddressOf options_HeaderFooterExporting


                Dim document = Me.SfDataGrid1.ExportToPdf(options)


                ' Set the page size explicitly to landscape

                document.PageSettings.Orientation = PdfPageOrientation.Landscape


                SaveFileDialog1.Filter = "PDF Files (*.pdf)|*.pdf"

                If SaveFileDialog1.ShowDialog = DialogResult.OK Then

                    document.Save(SaveFileDialog1.FileName)

                End If

            Catch ex As Exception

                MessageBox.Show("Error: " & ex.Message)

            End Try

        Else

            MsgBox("Please refresh the report before printing.")

        End If

    Catch ex As Exception

        MsgBox(ex.ToString)

    End Try

End Sub


Private Sub options_HeaderFooterExporting(ByVal sender As Object, ByVal e As PdfHeaderFooterEventArgs)

    ' Add your custom header/footer content here if needed

End Sub


1 Reply

SG Santhosh Govindasamy Syncfusion Team November 3, 2023 06:14 PM UTC

Hi Jeff,

We analyzed the mentioned problem "ExportToPdf not allowing landscape orientation" as per the provided code snippet. You directly exported the PdfDocument, and then only set the orientation, which is why the DataGrid refuses. Before exporting, you need to set the document orientation.

For your reference, we have attached the User Guide (UG) link for handling "Change PDF Page Orientation."

UG Link-> https://help.syncfusion.com/windowsforms/datagrid/exporttopdf#change-pdf-page-orientation

Regards,
Santhosh.G




Loader.
Up arrow icon