none
Print RDLC without Report Viewer either in Portrait or Landscape

    Question

  • I am currently using the code at this link - http://msdn.microsoft.com/en-us/library/ms252091%28v=vs.100%29.aspx to print my local rdlc report directly to the printer without the report viewer.

    It is working great except when I have a report that is landscape.  The following code does the export part and it is manually set for portrait.

     Private Sub Export(ByVal report As LocalReport)
            Dim deviceInfo As String = "<DeviceInfo>" & _
                "<OutputFormat>EMF</OutputFormat>" & _
                "<PageWidth>8.5in</PageWidth>" & _
                "<PageHeight>11in</PageHeight>" & _
                "<MarginTop>0.25in</MarginTop>" & _
                "<MarginLeft>0.25in</MarginLeft>" & _
                "<MarginRight>0.25in</MarginRight>" & _
                "<MarginBottom>0.25in</MarginBottom>" & _
                "</DeviceInfo>"
            Dim warnings As Warning()
            m_streams = New List(Of Stream)()
            report.Render("Image", deviceInfo, AddressOf CreateStream, warnings)
            For Each stream As Stream In m_streams
                stream.Position = 0
            Next
        End Sub

    I am wondering if there is a way to have it change it to landscape when the report is landscape.  I have reports in portrait and landscape and I print multiple reports at once and one might be portrait and another might be landscape.  I could make another sub for exporting the landscape reports or add an if statement to that sub for if the report is portrait or landscape but is there a way to know which reports are portrait and which are landscape?  How can I tell the program oh this report is landscape not portrait?

    This is the sub for actually printing the report...

    Private Sub PrintFiles() For Each row As DataGridViewRow In WofilesDataGridView.Rows If row.Cells(0) Is DBNull.Value Then Else Dim zReport As String = row.Cells(0).Value Dim report As New LocalReport() report.ReportPath = ("C:\MaintenanceTracker\MaintenanceTracker\Reports\" & zReport) report.DataSources.Add(New ReportDataSource("DataSet1", LoadSalesData())) Export(report) Print() End If Next End Sub

    So as you can see it is just going through a datagridview to find out which reports it needs to print.  So there is no way to tell it which are portrait and which are landscape.

    I hope that makes sense.  Thanks for any help you can provide.

    Stacy




    • Edited by tnswalker Friday, March 29, 2013 12:21 PM
    Friday, March 29, 2013 12:00 PM

All replies

  • In your Export sub, I think you can get the papersize of the report by using GetDefaultPageSettings() method on report object.

    PaperSize paperSize = report.GetDefaultPageSettings().PaperSize

    And then you can use Width and Height properties of the PaperSize class to determine if report is landscape or portrait.

    If you are using Visual Studio 2010 (Report Viewer), then PaperSize also comes with IsLandscape property that you can make use of.

    Hopefully this helps..

    Friday, March 29, 2013 2:47 PM
  • Thanks for your reply.

    I have been working with the PaperSize but it says it's a readonly.  I can't get it to return the value so I can view it.  If I paste your line of code how you have it I get an error PaperSize is a type and cannot be used as an expression.

    I am not using the reportViewer.  I print directly to the printer.  It will print the reports perfectly if they come out of the reportviewer, but the user doesn't want to view the report before printing that is why I have it printing directly to the printer.

    Thanks,

    Stacy

    Friday, March 29, 2013 5:15 PM
  • Sorry for improper usage of property in my code (it was infact untested code). But what I found interesting is that paper size is read only! Because I could see that this property has get accessor which meant to be returning the value!!

    You may not be using the report viewer, but the reference link you provided is using Microsoft.Reporting.Winforms under which LocalReport type is defined, which should have this read/write property unless I am practically wrong.

    Can I know which version of the Microsoft.ReportViewer.Winforms you are referencing to?

    Friday, March 29, 2013 7:46 PM
  • I'm not sure which version microsoft.ReportViewer.Winforms but I am using Visual Studio 2010 Professional and I am using SQL Server 2008 RTM.
    Friday, March 29, 2013 10:53 PM
  • Hi Stacy,

    From your description, you don’t know how to tell the program oh this report is landscape not portrait, right? Reporting Services does not provide explicit page orientation, such as portrait and landscape modes. Actually, Reporting Services prints a report in landscape or portrait based on the difference between the report width and height. So we needn’t tell the program oh this report is landscape not portrait. If the width is larger than the height, the report will be printed in landscape; otherwise, it will be printed in portrait.

    References:

    If you have any questions, please feel free to ask.

    Regards,
    Charlie Liao

    If you have any feedback on our support, please click here.   


    Charlie Liao
    TechNet Community Support

    Monday, April 01, 2013 2:57 AM
    Moderator
  • Thanks Charlie for your reply.  I am exporting to EMF and then printing directly to the printer.  I am telling the report in the export sub below the device info settings...

    Private Sub Export(ByVal report As LocalReport)
            Dim deviceInfo As String = "<DeviceInfo>" & _
                "<OutputFormat>EMF</OutputFormat>" & _
                "<PageWidth>8.5in</PageWidth>" & _
                "<PageHeight>11in</PageHeight>" & _
                "<MarginTop>0.25in</MarginTop>" & _
                "<MarginLeft>0.25in</MarginLeft>" & _
                "<MarginRight>0.25in</MarginRight>" & _
                "<MarginBottom>0.25in</MarginBottom>" & _
                "</DeviceInfo>"
            Dim warnings As Warning()
            m_streams = New List(Of Stream)()
            report.Render("Image", deviceInfo, AddressOf CreateStream, warnings)
            For Each stream As Stream In m_streams
                stream.Position = 0
            Next
        End Sub

    However, when I manually changed the deviceInfo settings to PageWidth 11 and PageHeight 8.5 it still doesn't print landscape.  It squishes it to fit Portrait.  I'm fairly new to this and afraid I am completely out of my league here trying to figure this out.  So your help is greatly appreciated.

    Thanks for all your help!

    Stacy


    • Edited by tnswalker Tuesday, April 02, 2013 5:19 PM
    Tuesday, April 02, 2013 5:18 PM
  • OK I can manually get it to print landscape if I change the Export subs values for the pagewidth and pageheight and also if I add printDoc.DefaultPageSettings.Landscape = True to the Print sub.

        Private Sub Print()
            If m_streams Is Nothing OrElse m_streams.Count = 0 Then
                Throw New Exception("Error: no stream to print.")
            End If
            Dim printDoc As New PrintDocument()
            If Not printDoc.PrinterSettings.IsValid Then
                Throw New Exception("Error: cannot find the default printer.")
            Else
                AddHandler printDoc.PrintPage, AddressOf PrintPage
                m_currentPageIndex = 0
                printDoc.DefaultPageSettings.Landscape = True
                printDoc.Print()
            End If
        End Sub

    I was thinking that I could put a variable in the reports that I could set if it is portrait or landscape and then read that parameter value so I knew if I needed to print Landscape or portrait.  Does that sound plausible?

    Thanks,

    Stacy

    Friday, April 05, 2013 3:34 PM