您可以使用ReportPageSettings.IsLandscape https://msdn.microsoft.com/en-us/library/microsoft.reporting.webforms.reportpagesettings.islandscape.aspx属性来验证报告是否被定义为横向(报表属性 > 页面设置 > 方向).
如果横向,您需要交换纸张宽度和纸张高度DeviceInfo
宣言。
Dim rdlLocalReport As New LocalReport
Dim strDeviceInfo As String
With rdlLocalReport.GetDefaultPageSettings
Dim intPaperSizeWidth As Integer = 0
Dim intPaperSizeHeight As Integer = 0
If .IsLandscape Then
intPaperSizeWidth = .PaperSize.Height
intPaperSizeHeight = .PaperSize.Width
Else
intPaperSizeWidth = .PaperSize.Width
intPaperSizeHeight = .PaperSize.Height
End If
strDeviceInfo = "<DeviceInfo>" _
& "<OutputFormat>EMF</OutputFormat>" _
& "<PageWidth>" & Strings.Replace(intPaperSizeWidth / 100, ",", ".") & "in</PageWidth>" _
& "<PageHeight>" & Strings.Replace(intPaperSizeHeight / 100, ",", ".") & "in</PageHeight>" _
& "<MarginTop>" & Strings.Replace(.Margins.Top / 100, ",", ".") & "in</MarginTop>" _
& "<MarginLeft>" & Strings.Replace(.Margins.Left / 100, ",", ".") & "in</MarginLeft>" _
& "<MarginRight>" & Strings.Replace(.Margins.Right / 100, ",", ".") & "in</MarginRight>" _
& "<MarginBottom>" & Strings.Replace(.Margins.Bottom / 100, ",", ".") & "in</MarginBottom>" _
& "</DeviceInfo>"
End With
如果你使用PrintDocument
你还需要相应地改变PageSettings.Landscape https://msdn.microsoft.com/en-us/library/system.drawing.printing.pagesettings.landscape(v=vs.110).aspx财产。
Dim printDoc As New PrintDocument
printDoc.DefaultPageSettings.Landscape = rdlLocalReport.GetDefaultPageSettings.IsLandscape