2014-01-30 105 views
3

我試圖以橫向或縱向打印本地報告。在無預覽的情況下在rdlc中打印風景/人像

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個不同的報告,一個在縱向模式下,一個在風景模式,但不要緊什麼值我更改頁寬和每頁,它總是在縱向打印。 我在11.7英寸和8.3英寸之間調換了寬度和高度,但它始終以縱向模式打印。

回答

0

您可以使用ReportPageSettings.IsLandscape屬性驗證報告是否定義爲橫向(報告屬性>頁面設置>方向)。

如果您需要在您的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屬性。

Dim printDoc As New PrintDocument 
printDoc.DefaultPageSettings.Landscape = rdlLocalReport.GetDefaultPageSettings.IsLandscape 
相關問題