Quantcast
Channel: SCN: Message List
Viewing all articles
Browse latest Browse all 9080

Crystal report viewer does not observe the PaperSize and PageOrientation setting

$
0
0

Hi:

 

My application is a 3 tier application, where the WinForm client is connected to the WCF Services hosted in IIS server.

The report is generated on server side using WCF service, and export as.rpt with data, the .rpt file is then sent to the WinForm client, the Crystal Report viewer is used to load the .rpt file for preview and print.

 

On server side I've Microsoft XPS Document Writer installed and set as default printer. On the client side if the default printer is XPS or Nitro PDF creator, the report can be view and print correctly, report design in landscape will be able to show in the landscape in CR viewer, report design using custom paper size (e.g. Half Letter), CR viewer able to show it in Half Letter.

 

The problem that I'm facing is when the default printer is set to HP LaserJet P1120 or others (I've tried Epson ESC/P Standard driver), the report is always shown in the portrait, and it will not be able to show in custom paper size either. Here is my code:

 

     Dim settings As New System.Drawing.Printing.PrinterSettings

     Dim rep as New ReportDocument

 

     rep.Load(sOutputFileName)     'The report is download from server and save in sOutputFileName

     SetReportPaperSize(rep, sPaperSizeName, False, settings) ' sPaperSizeName store the name of the custom paper used in the report

     CrViewer.ReportSource = rep




   Public Shared Sub SetReportPaperSize(rep As ReportDocument, paperSizeName As String, isHardCopy As Boolean, settings As Printing.PrinterSettings)

      Dim installedPrinters As Printing.PrinterSettings.StringCollection = Printing.PrinterSettings.InstalledPrinters

      Dim printers As New List(Of String)

      Dim sPrinter As String

 

      If installedPrinters.Count = 0 Then

         Return

      End If

 

      SetPrinterDefaultPaperSize(rep.PrintOptions, paperSizeName, settings)

 

      With rep.PrintOptions

         .PrinterName = settings.PrinterName

         .PaperSource = PaperSource.Auto

 

         If paperSizeName.Trim.Length > 0 Then

            .PaperSize = DirectCast(GetPapersizeId(paperSizeName, settings, rep.PrintOptions.PaperSize), CrystalDecisions.Shared.PaperSize)

         End If

      End With

   End Sub

    

   Public Shared Sub SetPrinterDefaultPaperSize(printOptions As PrintOptions, paperSizeName As String, settings As Printing.PrinterSettings)

      With settings.DefaultPageSettings

         If paperSizeName.Trim.Length = 0 Then

            . PaperSize = GetPaperSize (printOptions.PaperSize, settings)

         Else

            For Each size As Printing.PaperSize In settings.PaperSizes

               If size.PaperName.EqualsTo(paperSizeName) Then

                  .PaperSize = size

                  Exit For

               End If

            Next

         End If

 

         .Landscape = printOptions.PaperOrientation = PaperOrientation.Landscape

         .Margins.Top = printOptions.PageMargins.topMargin

         .Margins.Left = printOptions.PageMargins.leftMargin

         .Margins.Bottom = printOptions.PageMargins.bottomMargin

         .Margins.Right = printOptions.PageMargins.rightMargin

      End With

   End Sub


   Public Shared Function GetPaperSize(paperSizeId As Integer, defaultPrinterSettings As Printing.PrinterSettings) As Printing.PaperSize

      Dim settings As Printing.PrinterSettings = defaultPrinterSettings

      Dim result As Printing.PaperSize

 

      If settings Is Nothing Then

         settings = New Printing.PrinterSettings

      End If

 

      ' Default paper Size defined in the printer

      result = settings.DefaultPageSettings.PaperSize

 

      For Each size As Printing.PaperSize In settings.PaperSizes

         If size.RawKind = paperSizeId Then

            result = size

            Exit For

         End If

      Next

 

      Return result

   End Function

 

 

   Public Shared Function GetPapersizeId(paperSizeName As String, defaultPrinterSettings As Printing.PrinterSettings Optional defaultpaperSizeId As CrystalDecisions.Shared.PaperSize = CrystalDecisions.Shared.PaperSize.DefaultPaperSize) As Integer

      Dim settings As Printing.PrinterSettings = defaultPrinterSettings

      Dim result As Integer = defaultpaperSizeId

 

      If settings Is Nothing Then

         settings = New Printing.PrinterSettings

      End If

 

      If Not String.IsNullOrEmpty(paperSizeName) Then

         For Each size As Printing.PaperSize In settings.PaperSizes

            ' Height and Width in Printing.PaperSize is measure in hundredths of an inch

            If size.PaperName.EqualsTo(paperSizeName) Then

               result = size.RawKind

               Exit For

            End If

         Next

      End If

 

      Return result

   End Function

 

 

Setting the PrintOptions.PaperSize and PageOrientation seem like no effect on the viewer. My code to load the report to CR viewer is much more complicated than the code I show above, I've a background worker thread to download the report, and when the worker thread finished download the report from the server, it will assign the report to CRViewer. Do the changes in report PrintOption before assign to CRViewe and after assigning to CRViewer make any different?

 

I'm using VS2010, CR XI R2 (Version 11.5.3700.0). Please Help. Thanks

 

Regards

JC Voon


Viewing all articles
Browse latest Browse all 9080

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>