How to check no printer on a Crystal Report using the RAS SDK in .NET

Talked to an old customer today who was looking for a way to check No Printer on his Crystal Reports to get around an issue with not having the same printer driver installed on the BOE machine as the reports were designed against.

I checked and to my surprise I could not find any sample code posted except the ones I put on the forums so i decided to create this post for it.

Essentially there is no way to check the No Printer checkbox directly via code.  What you have to do is remove all of the print options from the Crystal Report and by default this will check the no printer button for you.

And at the same time if you have a Report with No printer checked on and want to change the orientation to landscape see this test app on how to and the section – private void btnSetPrinter_Click(object sender, System.EventArgs e

Printing Crystal Reports in .NET

Following are the VB.NET and C# code using the RAS SDK to accomplish this.

bq. Check No Printer with VB.NET

Check No Printer with C#

public class WebForm1 : System.Web.UI.Page

{

ReportClientDocument rcd;

ReportClientDocument rcd1;

PrintOptions pOpts;

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

{

// Put user code to initialize the page here

// create report client document

rcd = new ReportClientDocument();

// set report application server location

rcd.ReportAppServer = “127.0.0.1”;

// create a new report based on the report with no printer checked

object file = “C:
Reports
NoPrinterReport.rpt”;

rcd.Open(ref file, 0);

// copy out the print options from the no printer report

pOpts = new PrintOptionsClass();

pOpts = rcd.PrintOutputController.GetPrintOptions();

// create a new report based on the report with a printer selected

rcd1 = new ReportClientDocument();

// set report application server location

rcd1.ReportAppServer = “127.0.0.1”;

// create a new report

object file2 = “C:
Reports
PrinterReport.rpt”;

rcd1.Open(ref file2, 0);

//modify all of the print options and base them on the no printer reports print options and save over top of the existing report

rcd1.PrintOutputController.ModifyPrintOptions(pOpts);

rcd1.PrintOutputController.ModifyPrinterName(“”);

rcd1.PrintOutputController.ModifyPageMargins(pOpts.PageMargins.Left, pOpts.PageMargins.Right, pOpts.PageMargins.Top, pOpts.PageMargins.Bottom);

rcd1.PrintOutputController.ModifyPaperOrientation(CrPaperOrientationEnum.crPaperOrientationDefault);

rcd1.PrintOutputController.ModifyUserPaperSize(pOpts.PageContentHeight, pOpts.PageContentWidth);

rcd1.Save();

}

#region Web Form Designer generated code

override protected void OnInit(EventArgs e)

{

//

// CODEGEN: This call is required by the ASP.NET Web Form Designer.

//

InitializeComponent();

base.OnInit(e);

}

///

New NetWeaver Information at SAP.com

Very Helpfull

 

 

User Rating: Be the first one !

Comments (0)
Add Comment