问题描述
我正在尝试以横向或纵向打印本地报告.
I am trying to print a local report in either landscape or portrait.
private void Export(LocalReport report)
{
Warning[] warnings;
m_streams = new List<Stream>();
var deviceInfo = new StringBuilder();
deviceInfo.AppendLine("<DeviceInfo>");
deviceInfo.AppendLine("<OutputFormat>EMF</OutputFormat>");
//"11.7in", "8.3in"
deviceInfo.AppendLine("<PageWidth>11.7in</PageWidth>");
deviceInfo.AppendLine("<PageHeight>8.3in</PageHeight>");
deviceInfo.AppendLine("</DeviceInfo>");
report.Render("Image", deviceInfo.ToString(), CreateStream, out warnings);
foreach (var stream in m_streams) { stream.Position = 0; }
}
我有 2 个不同的报告,一个是纵向模式,一个是横向模式,但是我更改 PageWidth 和 PageSize 的值并不重要,它总是以纵向打印.我在 11.7 英寸和 8.3 英寸之间交换了宽度和高度,但它始终以纵向模式打印.
I have 2 different reports one in portrait mode and one in landscape mode but it doesn't matter what values I change for PageWidth and PageSize, its always printing in portrait.I've swapped width and height between 11.7in and 8.3in but its always printing in portrait mode.
推荐答案
您可以使用 ReportPageSettings.IsLandscape
属性以验证报告是否定义为横向(报告属性 > 页面设置 > 方向).
如果横向,您需要在 DeviceInfo
声明中交换纸张宽度和纸张高度.
If landscape you need to swap paper width and paper height in your DeviceInfo
declaration.
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
属性.
If you use PrintDocument
you also need to accordingly change PageSettings.Landscape
property.
Dim printDoc As New PrintDocument
printDoc.DefaultPageSettings.Landscape = rdlLocalReport.GetDefaultPageSettings.IsLandscape
这篇关于在没有预览的情况下在 rdlc 中打印横向/纵向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!