cancel
Showing results for 
Search instead for 
Did you mean: 

cannot programmatically change PaperOrientation or PaperSize

Former Member
0 Kudos

I have an .RPT file that I created with a Landscape paper orientation and a Letter paper size using Crystal Reports for Visual Studio (version 13.0.10) under VS 2013.  At run-time in my server-side .NET code, in a CrystalDecisions.CrystalReports.Engine.ReportDocument object, I changed the PaperOrientation (property PrintOptions.PaperOrientation) to Portrait and the PaperSize (property PrintOptions.PaperSize) to PaperA4.  However, when the report renders on the web client, it shows as Landscape and Letter as they were originally set in the .RPT - not using the overriding settings from the server-side code.

How can I get the report to change paper orientation/size programmatically?  Am I doing something wrong or is there a bug in Crystal Reports?  (and if it is a bug, is this something that will be fixed?)

Thanks in advance for your help!

Accepted Solutions (1)

Accepted Solutions (1)

former_member188030
Active Contributor
0 Kudos

Hi Trevor,

Could you try the code from below KBA and see if the issue reproduces.

http://search.sap.com/notes?id=0001561333&boj=/sap/bc/bsp/spn/scn_bosap/notes.do?access=69765F6D6F64...

- Bhushan

Senior Engineer

SAP Active Global Support

Follow us on Twitter

Got Enhancement ideas? Try the SAP Idea Place

Getting started and moving ahead with Crystal Reports .NET applications.

Former Member
0 Kudos


Thanks for your response.  I tried following along with the example link you included above.

First, I am using the web viewer under Crystal Reports for Visual Studio in a Web Form - your example was from a Windows Form.  Not sure if that makes a difference.

Second, I am not trying to print directly from my app - I just want the web document to appear in the web viewer with the specified paper size and orientation - either as a PDF or directly (for printing or exporting later).  Not sure if that makes a difference.

Third, I created the variable rptClientDoc as in the example and used the same definition (CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument).  However, I did not see class rptClientDoc.PrintOutputController appear from Intellisense (let alone the method rptClientDoc.PrintOutputController.ModifyPrintOptions).  Am I missing something?

Thanks!

former_member188030
Active Contributor
0 Kudos

If you are setting the paper orienation from 'Viewer - print - preferences' then the behavior is by design.

While setting the orientation from print preferences, it does not work. Same is mentioned in below KBs.

http://search.sap.com/notes?id=0001896405&boj=/sap/bc/bsp/spn/scn_bosap/notes.do?access=69765F6D6F64...

http://search.sap.com/notes?id=0001331213&boj=/sap/bc/bsp/spn/scn_bosap/notes.do?access=69765F6D6F64...

The solution would be to implement RAS .NET SDK code (KB from my earlier post) and set the orientation in code.

-Bhushan

Former Member
0 Kudos

I am trying to set the paper size and orientation on the web server side - so that the report is rendered with the correct size/orientation in the web viewer so that it is displayed that way in the web browser before anything is even printed.  I am not talking about setting the orientation from print preferences at all.

All of the examples you have provided are from Windows Forms - I am using ASP.NET Web Forms.

Re: the RAS .NET SDK code from your earlier post, I tried to follow that.  However, there are missing pieces.  I created the variable rptClientDoc as in the example and used the same class type to define it as in the example(CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument).  However, I did not see class rptClientDoc.PrintOutputController appear in Intellisense (let alone the method rptClientDoc.PrintOutputController.ModifyPrintOptions).  Am I missing something?

former_member188030
Active Contributor
0 Kudos

Could you elaborate on "I am trying to set the paper size and orientation on the web server side"?

How do you set the orientation on server?

The KBs apply to web apps as well.

Try this

CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();

        CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;

rptClientDoc = rpt.ReportClientDocument;

-Bhushan

Former Member
0 Kudos

Extending from your sample code above, here is an example of what I was doing (this was code that worked in the version Crystal Reports for VS 2005 / .NET 2.0) - in code that runs from the Page_Init event handler:

rpt.PrintOptions.PaperOrientation = CrystalDecisions.Shared.PaperOrientation.Portrait;

rpt.PrintOptions.PaperSize = CrystalDecisions.Shared.PaperSize.PaperA4

Questions I have are:

1)  Why doesn't this work anymore in this version of CR for VS?

2)  If I go with the examples you sent in the links from the KB, I'm still missing something.  When I create the variable rptClientDoc as you did (as type CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument), I'm still not seeing an option for rptClientDoc.PrintOutputController in Intellisense - so I can't see how to connect MYPRTOpts (defined as type CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions) to it.

former_member188030
Active Contributor
0 Kudos

Try this code. Works for me. Sets a portrait report to landscape.

using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using CrystalDecisions.Windows;
using CrystalDecisions.ReportAppServer.ClientDoc;
using CrystalDecisions.ReportAppServer.Controllers;
using CrystalDecisions.ReportAppServer.ReportDefModel;
using CrystalDecisions.ReportAppServer.CommonControls;
using CrystalDecisions.ReportAppServer.CommLayer;
using CrystalDecisions.ReportAppServer.CommonObjectModel;
using CrystalDecisions.ReportAppServer.ObjectFactory;
using CrystalDecisions.ReportAppServer.DataSetConversion;
using CrystalDecisions.ReportAppServer.DataDefModel;
namespace Passparameter
{
    public partial class Form1 : Form
    {
       
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           
            CrystalDecisions.CrystalReports.Engine.ReportDocument rd = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
            rd.Load(@"C:\CrystalReport.rpt");
            CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;
            rptClientDoc = rd.ReportClientDocument;
            System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument();
            CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions rasPROpts = new CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions();
            CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions MYPRTOpts = new CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions();
          
                pDoc.PrinterSettings.PrinterName = "Printer Name";
                MYPRTOpts.PrinterName = "Printer Name"; 
               // MYPRTOpts.PaperSize = (CrPaperSizeEnum)     pDoc.PrinterSettings.PaperSizes[cboCurrentPaperSizes.SelectedIndex].Kind;
                //MYPRTOpts.PaperSource = (CrPaperSourceEnum)     pDoc.PrinterSettings.PaperSources[cboCurrentPaperTrays.SelectedIndex].Kind;
                // added the below line to verify the changes work.
                MYPRTOpts.PaperOrientation = CrPaperOrientationEnum.crPaperOrientationLandscape;
            rptClientDoc.PrintOutputController.ModifyPrintOptions(MYPRTOpts);
            MessageBox.Show("Printer set.", "RAS", MessageBoxButtons.OK,MessageBoxIcon.Information );
            rptClientDoc.PrintOutputController.PrintReport(rasPROpts);
            MessageBox.Show("Printing report.", "RAS", MessageBoxButtons.OK,MessageBoxIcon.Information );

            crystalReportViewer1.ReportSource = rd;
        }
    }
}

Thanks,

Bhushan

Former Member
0 Kudos

I finally got it to work using your examples!  What threw me off was that rptClientDoc.PrintOutputController... didn't appear from Intellisense - however the code compiled and worked.  (Wondering why Intellisense didn't pick it up?)

Anyway, I got it to work with your help.  Thank you every much!

former_member188030
Active Contributor
0 Kudos

Happy to help .

Just a tip, dont write the CR code on Page_Load, it introduces issues with viewer. Use Page_Init or some other event.

Happy coding!!

- Bhushan

Senior Engineer

SAP Active Global Support

Follow us on Twitter

Got Enhancement ideas? Try the SAP Idea Place

Getting started and moving ahead with Crystal Reports .NET applications.


Former Member
0 Kudos

Thanks - I discovered that about the Page_Load.  I called the code from there originally because it worked from there under CR for VS 2005 (and discovered it didn't work until I moved it to Page_Init once I ported to the current version of CR for VS!)

Answers (0)