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

Re: CrystalReportViewer - Print with preference Landscape prints in Portrait

$
0
0

Hi Patrick,

 

I see why this isn't working for you... You have No printer checked on. This means you are setting the report to use the default Portrait layout. And because of this printing the report in any application is going to ignore changing the orientation.

 

If you download my test app create a new dummy report called "CloneHasPrinter" and set the page setting to landscape and Dissociate must be checked on also.

 

Now in my test app I added the below in BOLD, change the name of the report in this section:

 

private void btnSetPrinter_Click(object sender, System.EventArgs e)

{

    // THIS WORKS BUT IT DOESN'T UPDATE THE REPORT SETTINGS - No Printer to checked off

    System.Drawing.Printing.PrintDocument pDoc = new System.Drawing.Printing.PrintDocument();

    System.Drawing.Printing.PageSettings page = new System.Drawing.Printing.PageSettings();

 

    CrystalDecisions.CrystalReports.Engine.PrintOptions printOptions = rpt.PrintOptions;

 

    CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions rasPROpts = new CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions();

    CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions newOpts = new CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions();

    CrystalDecisions.ReportAppServer.ReportDefModel.PageMargins crMarg = new CrystalDecisions.ReportAppServer.ReportDefModel.PageMargins();

    CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions newOptsCloned = new CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions();

 

    CrystalDecisions.Shared.PrintLayoutSettings PrintLayout = new CrystalDecisions.Shared.PrintLayoutSettings();

 

    // DISPLAY = no printer.

    // See this blog on how to set no printer http://scn.sap.com/community/crystal-reports-for-visual-studio/blog/2010/09/15/how-to-check-no-printer-on-a-crystal-report-using-the-ras-sdk-in-net

    // requires cloning a report with no printer not checked and then using those properties in the real report

    // same is true is you have No Printer is checked on and you want to print to portrait it needs a dummy report set to be able to do that

    // in this case create a dummy report and set the Landscape option and enable Dissociate from your local printer.

    if (CrNoPrinter.Checked)

    {

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

        CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc2;

 

        rpt1.Load(@"c:\reports\CloneNoPrinterInfo.rpt"); // CloneHasPrinter - these reports are simply blank reports with the desired printer info saved in it.

        rptClientDoc2 = rpt1.ReportClientDocument;

        newOptsCloned = rptClientDoc2.PrintOutputController.GetPrintOptions();

        newOpts = newOptsCloned;

               

        if (chkDissociate.Checked == true)

            newOptsCloned.DissociatePageSizeAndPrinterPaperSize = true;

        else

            newOptsCloned.DissociatePageSizeAndPrinterPaperSize = false;

 

        rptClientDoc.PrintOutputController.ModifyPrintOptions(newOptsCloned);

        if (PROrientation.Text == "Portrait")

            rptClientDoc.PrintOutputController.ModifyPaperOrientation(CrPaperOrientationEnum.crPaperOrientationPortrait);

        else

            rptClientDoc.PrintOutputController.ModifyPaperOrientation(CrPaperOrientationEnum.crPaperOrientationLandscape);

 

...

 

Now it will print landscape....

 

You can preview the report to verify after clicking the Set Printer button...

 

Thanks again

Don


Viewing all articles
Browse latest Browse all 2807

Trending Articles



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