• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1642
  • Last Modified:

Print a Report in Landscape with VB.NET using Crystal Reports Viewer

I am using VB.Net 2005 and CR 11.5    Trying to give the user two options, either Preview or Direct Print.  I can get the Preview to work easily by using the .Show() method.  Problem is when I try to bypass the preview mode and send the report instead directly to the printer, it ends up printing any report in Potrait Orientation, even if the report is designed and designated as Landscape.

Currently using the objCRViewer.PrintReport() method, which brings up the printer selection dialog box.  I also tried bringing up my own MS Print Dialog and passing the parameters to the objReport.PrintToPrinter() method, but I keep getting a "Missing Parameters" error, but of course doesn't tell me what is missing.  Please help!
0
rev0304
Asked:
rev0304
  • 7
  • 7
1 Solution
 
mlmccCommented:
What code are you using?

I have found that reports switch properly between portrait and landscape if the printer defaults to landscape rather than portrait.  Not sure if that was the printer we used or if it is true for all printers.

mlmcc
0
 
rev0304Author Commented:
The code I am running is below, of course in context to the rest of my application.

There are two Print lines, one using the CRViewer [.PrintReport()] and the other using the Report Object [.PrintToPrinter()]... I commented out both lines

Hope this helps.
        '***************************************
        ' Initialize Variables
        '***************************************
        Dim objPrintDialog As New PrintDialog
 
        '***************************************
        ' Default Values
        '***************************************
        With objPrintDialog
            .AllowCurrentPage = False
            .AllowPrintToFile = False
            .AllowSelection = False
            .AllowSomePages = False
            .ShowDialog(Me)
        End With
 
        '***************************************
        ' Attach Data To Report
        '***************************************
        With Me._objReport
            .SetDataSource(Me._objDataSet)
            .Refresh()
        End With
 
        '***************************************
        ' Re-Instantiate Preview Form If Needed
        '***************************************
        If IsNothing(Me._objCRPreviewForm) OrElse Me._objCRPreviewForm.IsDisposed Then
            Me._objCRPreviewForm = New frmCrystalPreview
        End If
 
        '***************************************
        ' Print Report
        '***************************************
        With Me._objCRPreviewForm
            If Not IsNothing(Me._objParamFields) Then
                .CRViewer.ParameterFieldInfo = Me._objParamFields
            End If
            .CRViewer.ReportSource = Me._objReport
            With Me._objReport
                .PrintOptions.PrinterName = objPrintDialog.PrinterSettings.PrinterName
                '.PrintToPrinter(objPrintDialog.PrinterSettings.Copies, objPrintDialog.PrinterSettings.Collate, 0, 0)
            End With
            Me.Message_Close()
            '.CRViewer.PrintReport()
            .Dispose()
        End With

Open in new window

0
 
mlmccCommented:
Does your report require parameters?

mlmcc
0
Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

 
rev0304Author Commented:
Some do, not all of them.
0
 
mlmccCommented:
The REFRESH drops the parameters.  Try deleting that line

mlmcc
0
 
rev0304Author Commented:
I think you misunderstood, the parameters missing error I am getting is a VB IDE error regarding the PrintToPrinter() method, it is not a Crystal Error regarding report parameters. I am aware that .Refresh() drops parameters, which is why, if you noticed, I use the .Refresh() before I apply the parameters so that way I do not lose them.  But all in all, the Parameters are not my problem, they work perfectly fine.  My problem is being able to print in Landscape.
0
 
mlmccCommented:
It may be the nested WITH structure.  Try fully qualifying the PrintToPrinter.

mlmcc
0
 
rev0304Author Commented:
Nope, that didn't fix it.  :-(
0
 
mlmccCommented:
Is the printer dialog displayed or open?

mlmcc
0
 
rev0304Author Commented:
Yes the Printer Dialog displays perfectly fine.
0
 
mlmccCommented:
Is it still open when you try to reference it?

mlmcc
0
 
rev0304Author Commented:
If you are asking if I disposed the object, no.  The code above shows you that.  But it's a moot point, because the problem of not being able to directly print in Landscape happens using the PrintReport() method also, which uses it's own PrintDialog box.  The problem I am having ultimately is not a coding problem, but rather I think it's a Crystal problem.  Either Crystal has a bug, or there is an additional setting that I am unaware of to get it to print the way it should.
0
 
mlmccCommented:
No, since you are pulling information from the Printer Dialog, it must be open to use the information.  Generally once displayed to get off of it you click OK and it closes.

I have found that to get reports to print in landscape, the printer must be set to landscape as default.
For some reason reports switch to portrait with no problem but switching to landscape doesn't seem to work.

mlmcc
0
 
rev0304Author Commented:
That is unfortunate...since the software I am developing can use a multitude of printers, from a variety of clients.  Switching the printer itself to default to Landscape is not an option.  Then I see that my supposition was correct, Crystal has a bug in in with regards to printing in Landscape directly to printer without first previewing the report.  
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 7
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now