Skip to Content

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<br /><textarea cols=”75″ rows=”10″>Imports CrystalDecisions.ReportAppServer.ClientDoc

Imports CrystalDecisions.ReportAppServer.Controllers

Imports CrystalDecisions.ReportAppServer.ReportDefModel

Imports CrystalDecisions.ReportAppServer.DataDefModel

Public Class WebForm1

    Inherits System.Web.UI.Page

#Region ” Web Form Designer Generated Code “

    ‘This call is required by the Web Form Designer.

    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

    End Sub

    ‘NOTE: The following placeholder declaration is required by the Web Form Designer.

    ‘Do not delete or move it.

    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init

        ‘CODEGEN: This method call is required by the Web Form Designer

        ‘Do not modify it using the code editor.

        InitializeComponent()

        Dim rdc As ReportClientDocument

        ‘ create report client document

        rdc = New ReportClientDocument

        ‘ set report application server location

        rdc.ReportAppServer = “127.0.0.1”

        ‘ create a new report based on the no printer checked report

        rdc.Open(“C:\Reports\NoPrinterReport.rpt”)

        ‘ copy out the print options from the no printer report

        Dim pOpts As PrintOptions

        pOpts = rdc.PrintOutputController.GetPrintOptions.Clone(True)

        ‘ create a report client document

        Dim rcd1 As ReportClientDocument

        rcd1 = New ReportClientDocument

        rcd1.ReportAppServer = “127.0.0.1”

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

        rcd1.Open(“C:\Reports\PrinterReport.rpt”)

        ‘ modify all of the print options and base them on the no printer reports print options and save

        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()

    End Sub

#End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        ‘Put user code to initialize the page here

    End Sub

End Class

</textarea>

<blockquote>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);

}

///

To report this post you need to login first.

Be the first to leave a comment

You must be Logged on to comment or reply to a post.

Leave a Reply