2009-08-21 6 views

答えて

1

答えはNO、することはできませんということですあなた自身の解決策を書いている場合を除きます。レポートビューアコントロールはこれをサポートしていません。オプションは、カスタム印刷ソリューションを作成するか、RDLCファイルを操作して手動で設定を変更するかのいずれかです。

オンザフライでRDLCファイルを変更する場合は、RDLCファイルをメモリにロードし、XMLファイルを変更して新しいページ設定を指定してから、レポートビューアでRDLCファイルを再ロードする必要があります。

手動印刷を行うことを決定した場合、ここであなたが始めるのに役立ついくつかのVB.NETコードです:

Dim m_pageSettings As PageSettings   'Stores page settings for printout 
    Dim m_currentPage As Integer    'Used for index of pages 
    Private m_pages As New List(Of Stream)() 'Stores a stream for each pages 

    'Event fires when printDocument starts printing - reset page index to zero 
    Private Sub PrintDocument1_BeginPrint(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.BeginPrint 
    m_currentPage = 0 
    End Sub 

    'Function that prints all the pages included in the report 
    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage 
    Dim pageToPrint As Stream = m_pages(m_currentPage) 
    pageToPrint.Position = 0 

    Dim pageMetaFile As Metafile = New Metafile(pageToPrint)  'create an image(metafile) of the report page 
    Using (pageMetaFile) 
     'Create a rectangle the size of our report - include margins 
     ' Dim adjustedRect As Rectangle = New Rectangle(_ 
     ' e.PageBounds.Left - CType(e.PageSettings.HardMarginX, Integer), _ 
     ' e.PageBounds.Top - CType(e.PageSettings.HardMarginY, Integer), _ 
     ' e.PageBounds.Width, _ 
     ' e.PageBounds.Height) 

     Dim adjustedRect As Rectangle = New Rectangle(_ 
    e.PageBounds.Left, _ 
    e.PageBounds.Top, _ 
    e.PageBounds.Width, _ 
    e.PageBounds.Height) 

     e.Graphics.FillRectangle(Brushes.White, adjustedRect) 'Fill rectangle with WHITE background 
     e.Graphics.DrawImage(pageMetaFile, adjustedRect)  'Draw report in rectangle - this will be printed 
     m_currentPage = m_currentPage + 1 
     e.HasMorePages = m_currentPage < m_pages.Count   'If more pages are left - keep processing 
    End Using 
    End Sub 

    'Event fires when PrintDocument queries for PageSettings. Return a copy of m_pagesettings. 
    Private Sub PrintDocument1_QueryPageSettings(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.QueryPageSettingsEventArgs) Handles PrintDocument1.QueryPageSettings 
    e.PageSettings = CType(m_pageSettings.Clone, PageSettings) 
    End Sub 

    'Render the report in a EMF - This function creates metafiles(images) of each page in the report 
    Private Sub RenderAllLocalReportPages(ByVal localReport As LocalReport) 
    Dim deviceInfo As String = CreateEMFDeviceInfo() 'Enhanced MetaFile 
    Dim warnings As Warning() = Nothing 
    m_pages.Clear() 
    localReport.Render("IMAGE", deviceInfo, AddressOf LocalReportCreateStreamCallback, warnings) 
    End Sub 

    'Callback function used with RenderAllLocalReportPages 
    Private Function LocalReportCreateStreamCallback(ByVal name As String, ByVal extension As String, ByVal encoding As Encoding, ByVal mimeType As String, ByVal willSeek As Boolean) As Stream 
    Dim stream As New MemoryStream() 
    m_pages.Add(stream) 
    Return stream 
    End Function 

    Private Function CreateEMFDeviceInfo() As String 
    Dim paperSize As PaperSize = m_pageSettings.PaperSize 
    Dim margins As Margins = m_pageSettings.Margins 

    'The device info string defines the page range to print as well as the size of the page. 
    'A start and end page of 0 means generate all pages. 
    Return String.Format(CultureInfo.InvariantCulture, "<DeviceInfo><OutputFormat>emf</OutputFormat><StartPage>0</StartPage><EndPage>0</EndPage><MarginTop>{0}</MarginTop><MarginLeft>{1}</MarginLeft><MarginRight>{2}</MarginRight><MarginBottom>{3}</MarginBottom><PageHeight>{4}</PageHeight><PageWidth>{5}</PageWidth></DeviceInfo>", ToInches(margins.Top), ToInches(margins.Left), ToInches(margins.Right), ToInches(margins.Bottom), ToInches(paperSize.Height), ToInches(paperSize.Width)) 
    End Function 

    'Convert report printing size to inches 
    Private Shared Function ToInches(ByVal hundrethsOfInch As Integer) As String 
    Dim inches As Double = hundrethsOfInch/100.0R 
    Return inches.ToString(CultureInfo.InvariantCulture) & "in" 
    End Function 

うまくいけば、このことができます。

+0

これは役に立たないかもしれません。 –

関連する問題