cancel
Showing results for 
Search instead for 
Did you mean: 

How do you set the Crystal Report Viewer Printer to Duplex

Former Member
0 Kudos

Using the code below I can print in duplex mode, but this does not let me view a report before printing

How do I set the Printer in the Viewer Control Bar of the Crystal Report Viewer to Duplex Printing programmatically rather than having to manually select Duplex through the preferences option?

I have searched but the only example code I found produces errors in the code and will not run

Private myReport As ReportDocument

myReport = New ReportDocument()

myReport.PrintOptions.PaperSize = PaperSize.PaperA4

myReport.PrintOptions.PaperOrientation = PaperOrientation.Portrait

myReport.PrintOptions.PrinterDuplex = PrinterDuplex. Vertical

myReport.PrintToPrinter(3, False, 0, 0)

In my VB6 Project that I am converting to VB.NET when I added Report.PrinterDuplex = crPRDPVertical, this allowed me to view the report and then print with Duplex without having to set the Print Preferences manualy

I found 1386475 - How to set printer name and print job title at runtime using Report Application Server SDK for Visual Studio .NET

But this causes errors

Imports CrystalDecisions.ReportAppServer.ClientDoc

Imports CrystalDecisions.ReportAppServer.Controllers

Dim boReportClientDocument As ISCDReportClientDocument

Dim boPrintOutputController As PrintOutputController

Dim boPrintReportOptions As New PrintReportOptions

Edited by: DavidMills on Feb 18, 2011 11:58 AM

Accepted Solutions (1)

Accepted Solutions (1)

Adam_Stone
Active Contributor
0 Kudos

If you say that certain code causes errors, it might be helpful to include those errors in your post.

Former Member
0 Kudos

sorry. the error only shows a message when the mouse hovers over the two Import statements

Message is Namespace or type specified in the Imports doesnu2019t contain any pubic member or cannot be found

Which means that the Dim statements say Type ISCDReportClientDocument not defined

I have

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared

Imports CrystalDecisions.ReportAppServer

Imports CrystalDecisions.ReportAppServer.ClientDoc

Imports CrystalDecisions.ReportAppServer.Controllers

Edited by: DavidMills on Feb 18, 2011 12:43 PM

Adam_Stone
Active Contributor
0 Kudos

Hovering over which imports statements are throwing this error? These sound like you are missing a reference or something similar in the project which prevents the solution from being built.

0 Kudos

Hi David,

What version of Visual Studio are you using?

What version of the CR assemblies?

Do you have a standalone version of Crystal Reports or using CR Basic included with VS?

Thank you

Don

Former Member
0 Kudos

Hi Don

I am using Visual Studio 2010 and the Crytal Reports for VS2010 CR2010

SAP CRYSTAL REPORTS FOR VISUAL STUDIO 2010

I do not have a standalone version of Crystal Reports

Regards

David

Former Member
0 Kudos

Hi Adam

You can add Imports CrystalDecisions.ReportAppServer without any problems

But there are no options in the list to add ClientDoc or Controllers to the CrystalDecisions.ReportAppServer

Either I have found the wrong example code or I need something more installed than I do have

at the moment I am using Visual Studio 2010 and the Crytal Reports for VS2010

Regards

David

Former Member
0 Kudos

[1215578 - Can not import "CrystalDecisions.ReportAppServer.ClientDoc" Assembly |http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_bi/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333233313335333533373338%7D.do]

This may be the answer to the problem - will need to try the solution suggested

Symptom

When adding the component "CrystalDecisions.ReportAppServer.ClientDoc" to be a reference in a .NET project the assembly is not imported into the project. The namespace is not listed as the import is being defined.

Why is the assembly not imported into the project and how can you ensure that it is imported?

Resolution

The assemply is not imported into the project because of a known issue.

To resolve this issue, run the following commands at a "Visual Studio .NET Command Prompt".

Copy C:WINNTassemblyGACCrystalDecisions.ReportAppServer.ClientDoc9.2.3300.0__692fbea5521e1304CrystalDecisions.ReportAppServer.ClientDoc.dll "C:ProgrammeCommon FilesCrystal Decisions2.0managed"

Copy C:WINNTassemblyGACCrystalDecisions.ReportAppServer.CommLayer9.2.3300.0__692fbea5521e1304CrystalDecisions.ReportAppServer.commlayer.dll "C:ProgrammeCommon FilesCrystal Decisions2.0managed"

Copy C:WINNTassemblyGACCrystalDecisions.ReportAppServer.XmlSerialize9.2.3300.0__692fbea5521e1304CrystalDecisions.ReportAppServer.xmlserialize.dll "C:ProgrammeCommon FilesCrystal Decisions2.0managed"

.NET should then display the assembly in the project.

There is only one problem with this fix there is no "C:ProgrammeCommon FilesCrystal Decisions2.0managed directory

Presumably it should be C:Program FilesCommon FilesCrystal Decisions but that also does not exist

Edited by: DavidMills on Feb 18, 2011 4:13 PM

0 Kudos

Hi David,

That Kbase is for Visual Studio 2003 which used CR version 9. So I doubt it's the cause or solution.

The problem is the PrintToPrinter method is the CR Basic engine and you should be using the PrintOutputController within RAS. The Engine and PrintToPrinter method does not get updated.

This is C# but add all of these to your project:


using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
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 System.Data.OleDb;
using CrystalDecisions.ReportAppServer.DataSetConversion;
using CrystalDecisions.ReportAppServer.DataDefModel;

And then this uses a dialog box to select and fill in the info but you should be able to use the options in your app:

private void btnSetPrinter_Click(object sender, System.EventArgs e)
{
	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();
	if (rdoCurrent.Checked) 
	{
		pDoc.PrinterSettings.PrinterName = cboCurrentPrinters.Text;

        MYPRTOpts.PrinterName = cboCurrentPrinters.Text;
        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;
        MYPRTOpts.PrinterDuplex = CrPrinterDuplexEnum.crPrinterDuplexVertical;
	}
	else 
	{
		pDoc.PrinterSettings.PrinterName = cboDefaultPrinters.Text;

        MYPRTOpts.PrinterName = cboDefaultPrinters.Text;
        MYPRTOpts.PaperSize = (CrPaperSizeEnum)
			pDoc.PrinterSettings.PaperSizes[cboDefaultPaperSizes.SelectedIndex].Kind;
        MYPRTOpts.PaperSource = (CrPaperSourceEnum)
			pDoc.PrinterSettings.PaperSources[cboDefaultPaperTrays.SelectedIndex].Kind;
        MYPRTOpts.PrinterDuplex = CrPrinterDuplexEnum.crPrinterDuplexVertical;
	}
    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 ); 

}

Thank you

Don

0 Kudos

And I should also add how to set the report client doc:



public class frmMain : System.Windows.Forms.Form
{
    CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
    CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;
...

private void btnOpenReport_Click(object sender, System.EventArgs e)
{
    rptClientDoc = new CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocument(); // ReportClientDocumentClass();

    openFileDialog.Filter = "Crystal Reports (*.rpt)|*.rpt|Crystal Reports Secure (*.rptr)|*.rptr";
    openFileDialog.FilterIndex = 1;

	if (openFileDialog.ShowDialog() == DialogResult.OK) 
	{
		btnOpenReport.Enabled = false;
		btnSaveRptAs.Enabled = false;
		object rptName = openFileDialog.FileName;
     
        try
        {
            rpt.Load(rptName.ToString());
            rptClientDoc = rpt.ReportClientDocument;
        }
        catch (Exception ex)
        {
            MessageBox.Show("ERROR: " + ex.Message);
            return;
        }
...

Thank you

Don

Former Member
0 Kudos

Thank you for the reply and the code Don

But I still need to solve the problem of all these not being recognised as valid

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;

all the above show = Message is Namespace or type specified in the Imports doesnu2019t contain any pubic member or cannot be found

using CrystalDecisions.ReportAppServer is accepted and does not show a problem

Is there a reference that has to be added to the project to solve why the last part of the option after using CrystalDecisions.ReportAppServer is not recognised?

Regards

David

0 Kudos

Hi David,

Set your Framework to 4.0, not the client and then they should show up. If they still don't then there is something wrong either with Visual Studio or CR for VS. Also set your CPU for x86 or x64 only, do not use Any CPU.

Try doing a repair install of both and be sure you are logging in as local PC administrator.

Also, what version of VS are you using? MS does not support "plug-ins" in the Express version of VS so Cr will not install properly since CR for VS 2010 is considered a plug-in.

Thank you

Don.

Former Member
0 Kudos

Hello Don

I have repaired VS2010 and reinstalled CR2010 and restarted the computer after doing this

Problem still remains

Namespace or type specified in the Imports 'CrystalDecisions.ReportAppServer.ClientDoc' doesn't contain any public member or cannot be found. Make sure the namespace or the type is defined and contains at least one public member. Make sure the imported element name doesn't use any aliases

I have VS2010 Proffessional

I do have VS Express VB 2008 installed but that is only becuse it has the upgrade wizard from VB6 to the new VB but I am not using the Express Version other than for the conversion

I am only working with VS2010 and the CR2010 through that

I have set the Framework to 4.0 version - I had done this before when I read one of the articles when first installing CR2010

I have the CPU for x86

I only work as local PC administrator

Is there a need to uninstall the Express 2008 version of VS even if it is not being used with CR2010?

Regards

David

0 Kudos

Hi David,

I don't know if you need to uninstall Express. It may make a difference in the order you installed them though. CR may be finding the express version which won't work so it's not integrating into VS 2010 properly.

When you add the CR References to your Project are you browsing to the files or using the objects listed under the .NET tab? Be patient, .NET takes it time to list the CR Assemblies. If you are using the .NET tab try browsing to the C:\Windows\assembly and add them that way...

Things to do:

Go to C:\Windows\assembly and see if the version 13 dll's are there.

If they are then go to: C:\Program Files (x86)\SAP BusinessObjects\Crystal Reports for .NET Framework 4.0\Common\SAP BusinessObjects Enterprise XI 4.0\logging and look through the CR4VS_0.log file for any errors and/or references to the Express location. If there are then you'll have to uninstall Express, and likely do a repair of Vs 2010 and then repair or reinstall CR for VS 2010.

Thanks again

Don

Former Member
0 Kudos

Hi Don

I will try your suggestions

I have loaded an image of the list of options that show when you try to add to Imports CrystalDecisions.ReportAppServer

http://www.david-mills.com/cr2010.htm

I am not sure about the 13 DLLs in C:\Windows\assembly - there is a very long list of assemly names based on CrystalDecisions.CrystalReports.Design but I cannot see any files *.dll as you do in for example the System32 directory

The log file has Crystal Reports 2008 Runtime Setup - but no reference to VS Express 2008

Regards

David

I uninstalled Visual Basic Express 2008, reinstalled CR2010 after that, but that made no difference

Edited by: DavidMills on Feb 19, 2011 1:50 AM

Former Member
0 Kudos

Hello Don

What program installs the ClientDoc.dll etc needed for the CrystalDecisions.ReportAppServer additions?

Tried using Search to find ClientDoc.dll and that does not produce any result

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;

Regards

David

Former Member
0 Kudos

Hi Don

Regarding your request to Go to C:\Windows\assembly and see if the version 13 dll's are there.

I was struggling with that and found this on the internet

http://blogs.runatserver.com/lppinson/post/2009/04/29/how-to-retrieve-a-dll-from-the-gac.aspx

Using the Command Prompt window and going back to DOS commands CD windows\assembly\gac produced a list as in the image I have on http://www.david-mills.com/clientdoc.htm

That shows a directory C:\Windows\assembly\GAC\CrystalDecisions.ReportAppServer.ClientDoc plus others - is that what you needed me to find?

Regards

David

I found C:\Windows\assembly\GAC_MSIL\CrystalDecisions.ReportAppServer.ClientDoc and ClientDoc.dll is listed

screen shot is at http://www.david-mills.com/clientdoc.htm

Edited by: DavidMills on Feb 19, 2011 11:42 AM

Former Member
0 Kudos

Hello Don

I have made progress but now have new error messages

I have

Imports System.Data

Imports CrystalDecisions.CrystalReports

Imports CrystalDecisions.CrystalReports.Engine

Imports CrystalDecisions.Shared

Imports CrystalDecisions.ReportAppServer.ClientDoc

Imports CrystalDecisions.ReportAppServer.Controllers

Imports CrystalDecisions.ReportAppServer.ReportDefModel

Imports CrystalDecisions.ReportAppServer.CommonControls

Imports CrystalDecisions.ReportAppServer.CommLayer

Imports CrystalDecisions.ReportAppServer.CommonObjectModel

Imports CrystalDecisions.ReportAppServer.ObjectFactory

Imports System.Data.OleDb

Imports CrystalDecisions.ReportAppServer.DataSetConversion

Imports CrystalDecisions.ReportAppServer.DataDefModel

and while they are now all importing that creates these new error messages

'DataSet' is ambiguous, imported from the namespaces or types 'CrystalDecisions.ReportAppServer.DataDefModel, System.Data'

'TextObject' is ambiguous, imported from the namespaces or types 'CrystalDecisions.ReportAppServer.ReportDefModel, CrystalDecisions.CrystalReports.Engine'.

'Section' is ambiguous, imported from the namespaces or types 'CrystalDecisions.ReportAppServer.ReportDefModel, CrystalDecisions.CrystalReports.Engine'

DataSet I am using for the information that I need to customise in the TextObject

Section I am using to control the height based on the Custom text requirements

I had Dim txtObj As TextObject from the example in your notes on how to customise text

Dim txtObj As TextObject

txtObj = myReport.ReportDefinition.ReportObjects("Text1")

txtObj.Text = "testing"

Regards

David

0 Kudos

Hi David,

When using ADO.NET with the Microsoft .NET Framework 4.0, the following setting must be added to the applicationu2019s configuration file:

<configuration>

<startup useLegacyV2RuntimeActivationPolicy="true">

<supportedRuntime version="v4.0"/>

</startup>

</configuration>

Thank you

Don

Former Member
0 Kudos

Hello Don

Thank you for the reply - I did make that change when I first installed the CR2010, I read one of the notes that was on the download page

But while I have managed to clear the errors when the following is added

Imports System.Data

'Imports CrystalDecisions.CrystalReports

'Imports CrystalDecisions.CrystalReports.Engine

'Imports CrystalDecisions.Shared

'Imports CrystalDecisions.ReportAppServer.ClientDoc

'Imports CrystalDecisions.ReportAppServer.Controllers

'Imports CrystalDecisions.ReportAppServer.ReportDefModel

'Imports CrystalDecisions.ReportAppServer.CommonControls

'Imports CrystalDecisions.ReportAppServer.CommLayer

'Imports CrystalDecisions.ReportAppServer.CommonObjectModel

'Imports CrystalDecisions.ReportAppServer.ObjectFactory

'Imports System.Data.OleDb

'Imports CrystalDecisions.ReportAppServer.DataSetConversion

'Imports CrystalDecisions.ReportAppServer.DataDefModel

I then have an error message

Error = A reference was created to embedded interop assembly 'CrystalDecisions.ReportAppServer.ClientDoc' because of an indirect reference to that assembly from assembly 'CrystalDecisions.CrystalReports.Engine'. Consider changing the 'Embed Interop Types' property on either assembly.

and so far I have not found how to fix that error

Plus while they are now all importing that creates these new error messages

'DataSet' is ambiguous, imported from the namespaces or types 'CrystalDecisions.ReportAppServer.DataDefModel, System.Data'

'TextObject' is ambiguous, imported from the namespaces or types 'CrystalDecisions.ReportAppServer.ReportDefModel, CrystalDecisions.CrystalReports.Engine'.

'Section' is ambiguous, imported from the namespaces or types 'CrystalDecisions.ReportAppServer.ReportDefModel, CrystalDecisions.CrystalReports.Engine'

DataSet I am using for the information that I need to customise in the TextObject

Section I am using to control the height based on the Custom text requirements

I had Dim txtObj As TextObject from the example in your notes on how to customise text

Dim txtObj As TextObject

txtObj = myReport.ReportDefinition.ReportObjects("Text1")

txtObj.Text = "testing"

Not solved that so far

Regards

David

0 Kudos

Hi David,

The reason for those errors is now because you are using both the Engine and RAS and they use the same names you need to fully qualify them now so the app knows which to use, Engine or RAS API.

So depending on which engine you declared the text object against depend on the fully qualified line you use.

I can't give you specific samples because I don't know your whole code or subroutine.

Also, when using the RAS you use a different method to get the same object.

Use the Object Browser and you'll find the various methods you can use and also refer to the Developers SDK help file

High light the function and hit the F1 key and it should open up the help file.

See this [Kbase |http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_bi/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333533333330333933383339%7D.do]on how to enable help...

Thank you

Don

Former Member
0 Kudos

Hello Don

Thank you for your reply and information which is appreciated

But I still have a problem

When I go into the project properties and add the references so that the Import references are valid I am left with one one warning / error I cannot cure

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;

A reference was created to embedded interop assembly 'stdole' because of an indirect reference to that assembly from assembly 'CrystalDecisions.ReportAppServer.CommonControls'. Consider changing the 'Embed Interop Types' property on either assembly

By chaning 'Embed Interop to false I can cure the error messages for all of the assemblies other than the one to stdole

I think that I need to create a new project and to try to resolve making the RAS API work

Having already created a report with the Engine in the present project, I seem to create a whole lot of new errors and warnings by trying to change to RAS

With the Report that I have created with the Engine the ReportRequestStatus.NumberOfPages returns 0 if I use PrintToPrinter(1, False, 0, 0) and do not load the report into the viewer

If I load the report into the Viewer ReportRequestStatus.NumberOfPages only returns a number if I first

use CrystalReportViewer1.RefreshReport()

The reference help page for ReportRequestStatus.NumberOfPages does not indicate that the report has to be loaded into the viewer or that the RefreshReport has to be used

So I am not sure if I am not using the ReportRequestStatus.NumberOfPages correctly

Regards

David

0 Kudos

Hi David,

You can mix both engines, just declare them both with different report object names. Here's all of my references:


using System;
using System.IO;
using System.Xml;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
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 System.Data.OleDb;
using CrystalDecisions.ReportAppServer.DataSetConversion;
using CrystalDecisions.ReportAppServer.DataDefModel;
using CrystalDecisions.ReportSource;
using CrystalDecisions.Windows.Forms;
using System.Data.SqlClient;
using System.Runtime.InteropServices;

    public class frmMain : System.Windows.Forms.Form
    {
        CrystalDecisions.CrystalReports.Engine.ReportDocument rpt = new CrystalDecisions.CrystalReports.Engine.ReportDocument();
        CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument rptClientDoc;
...

My file open dialog:

        private void btnOpenReport_Click(object sender, System.EventArgs e)
        {
            rptClientDoc = new CrystalDecisions.ReportAppServer.ClientDoc.ReportClientDocument(); 

            openFileDialog.Filter = "Crystal Reports (*.rpt)|*.rpt|Crystal Reports Secure (*.rptr)|*.rptr";
            openFileDialog.FilterIndex = 1;

	        if (openFileDialog.ShowDialog() == DialogResult.OK) 
	        {
		        btnOpenReport.Enabled = false;
		        btnSaveRptAs.Enabled = false;
		        object rptName = openFileDialog.FileName;
                try
                {
                    rpt.Load(rptName.ToString());
                    rptClientDoc = rpt.ReportClientDocument;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("ERROR: " + ex.Message);
                    return;
                }

                MessageBox.Show(rptClientDoc.MajorVersion.ToString() + "." + rptClientDoc.MinorVersion.ToString());
                
				MessageBox.Show("Report opened.","RAS",MessageBoxButtons.OK,MessageBoxIcon.Information );
				btnOpenReport.Enabled = true;
				btnSaveRptAs.Enabled = true;

                //MessageBox.Show(rpt.RecordSelectionFormula, "my record: ", MessageBoxButtons.OK, MessageBoxIcon.Information);

                MessageBox.Show(rpt.ReportRequestStatus.NumberOfPages.ToString(), "Number of Pages: ", MessageBoxButtons.OK, MessageBoxIcon.Information);

			}
		}

As for the page number I use it off the Engine report object:

MessageBox.Show(rpt.ReportRequestStatus.NumberOfPages.ToString(), "Number of Pages: ", MessageBoxButtons.OK, MessageBoxIcon.Information);

And it works for me...

Thank you

Don

Former Member
0 Kudos

Thank you Don for the code

I started a new project using your code as in your last reply and that eliminated the errors and warnings that I had in the project that I had already started

The only note that I find on the website to set the printer to Duplex is 1386475 - How to set printer name and print job title at runtime using Report Application Server SDK for Visual Studio .NET but that appears to be for a previous version of Visual Studio and not for VS2010 and CR2010

I still receive a 0 for number of pages with MessageBox.Show(rpt.ReportRequestStatus.NumberOfPages.ToString(), "Number of Pages: ", MessageBoxButtons.OK, MessageBoxIcon.Information) where I presume it should show 1 unless the numbering starts at 0

Is there a Note or Code example on the website for setting the printer to Duplex printing?

Regards

David

0 Kudos

Hi David,

Check my reply on Posted: Feb 18, 2011 5:48 PM

MYPRTOpts.PrinterDuplex = CrPrinterDuplexEnum.crPrinterDuplexVertical;

Thanks again

Don

Former Member
0 Kudos

Hello Don

Sorry my last reply was not clear - did it late last night and was confusing two issues - printing direct to the printer in Duplex and viewing the Report in the CR Viewer with the CR Viewer Printer pre-set and set to Duplex printing

I can make the report print in Duplex without the CR Viewer using

myReport = New ReportDocument()

myReport.PrintOptions.PaperSize = PaperSize.PaperA4

myReport.PrintOptions.PaperOrientation = PaperOrientation.Portrait

myReport.PrintOptions.PrinterDuplex = PrinterDuplex. Vertical

myReport.PrintToPrinter(3, False, 0, 0)

But based on your code

MYPRTOpts.PrinterName = cboCurrentPrinters.Text

MYPRTOpts.PaperOrientation = CrPaperOrientationEnum.crPaperOrientationLandscape

MYPRTOpts.PrinterDuplex = CrPrinterDuplexEnum.crPrinterDuplexVertical

rptClientDoc.PrintOutputController.ModifyPrintOptions(MYPRTOpts)

I can change the printer and the paper orientation, but even with a report which is several pages long, the printer does not change to Duplex printing - the report does load and print but not in Duplex - not sure why

But where I was trying to get to was to load the report into the Viewer and change the printers preferences to Duplex printing

I can change the printer and the paper orientation for the printer in the CR Viewer but not set the Duplex prference

With my VB6 program and Crystal Reports I could use Report.PrinterDuplex = crPRDPVertical, this allowed me to view the report and then print with Duplex without having to set the Print Preferences manualy to Duplex

I was hoping that I could perform a similar control in VS2010 / CR2010

I did find that rpt.ReportRequestStatus.NumberOfPages returns 0 for 1 page and the number of pages when there is more than one page - I was expecting it to return 1 rather than 0 for a one page report as was the case with the VB6 code Report.PrintingStatus.NumberOfPages

Regards

David

0 Kudos

Hi David,

That is why we ask one question per post. How about posting a new question for the page number and leave this one for the subject.

What tool are you using to verify the Duplex flag is enabling?

Try this:

MYPRTOpts.DissociatePageSizeAndPrinterPaperSize = true; and test with false also;

You can also set this in the report options also.

Thank you

Don

Former Member
0 Kudos

Hi Don

My apologies if this posting has become confused by two issues

The Thread did start with the issue of how to set the printer in the Viewer to Duplex - the issue of the number of pages crept in because I thought that this was possibly related and the reason that I was having a problem with the Duplex printing not being set.

Do you want me to create a new posting and start again?

Regards

David

My original post was as copied below:-

Using the code below I can print in duplex mode, but this does not let me view a report before printing

How do I set the Printer in the Viewer Control Bar of the Crystal Report Viewer to Duplex Printing programmatically rather than having to manually select Duplex through the preferences option?

I have searched but the only example code I found produces errors in the code and will not run

Private myReport As ReportDocument

myReport = New ReportDocument()

myReport.PrintOptions.PaperSize = PaperSize.PaperA4

myReport.PrintOptions.PaperOrientation = PaperOrientation.Portrait

myReport.PrintOptions.PrinterDuplex = PrinterDuplex. Vertical

myReport.PrintToPrinter(3, False, 0, 0)

In my VB6 Project that I am converting to VB.NET when I added Report.PrinterDuplex = crPRDPVertical, this allowed me to view the report and then print with Duplex without having to set the Print Preferences manualy

Former Member
0 Kudos

Hi Don

Your question = What tool are you using to verify the Duplex flag is enabling?

I have loaded the report into the CR report viewer and with a report that has more than one page

If I go to Printer Preferences before printing when you Click on the CR Viewer Print Button, the Print Option for Duplex is not checked and if you then print, the printing is single sided

In my VB6 program when using the Cystal Reports Viewer, if I look at the Printer Preferences the Duplex option is set by the code in the VB6 program, and that is what I have been struggling to re-create with the VS2010 and CR2010 code

Regards

David

0 Kudos

Ah.. I get it now.... Sorry about that.

The typical UI does not disply that option. Which means it could be a .NET Printer limitation.

So in your default printer setup in Printers etc. of control panel or where ever it is if you configure your printer do you have the option there to set Duplex?

If so then CR should be able to use it. I don't believe it will show up in the options though. It's still a .NET printer driver configuration option.

VB 6 and the RDC may have simply exposed it because we used the DEVMODE structure to get the printer option/configuration. .NET may not expose it so we can't get to it.... but it may need to be turned on first.

I believe the problem is it doesn't show up in the Printer dialog as an option correct? It's not that it may not be using it which we can't verify?

Thanks again

Don

Former Member
0 Kudos

Hi Don

The answer then presumably is that I have to find a method of setting the printer option before loading the CR Viewer rather than that CR options allow the Duplex to be set on the CR Viewer Printer - I need VB code to change the printer defaults first

If I go into the Windows Control Panel and then Printers I can preset the printer to Duplex so that all printing is Duplex, I need to find out how that is done through code

In all the searching I have done, I did find one article on a Forum where someone had written code to set the printer Duplex option but it was quite a large chunk of code and they were having problems with making it work

Basically I should be chasing around Visual Studio on how to set the printer through code rather than that Crystal Reports can do that in VB Net as it did in the VB6 version

Thank you for the help and sorry it has been such a long issue

Regards

David

0 Kudos

Hi David,

Bottom line is yes you are correct. Once you have the options set then setting the printer to the updated info Crystal will use those settings.

CR used to have limited options in COM, we had to map from DEVMODE to COM to expose each property by adding the API to use it at runtime. In crpe32 and a Win32 app you simply used the DEVMODE structure. Crystal would copy the DEVMODE from the Printer configured on your PC and then changing the properties in that CR DEVMODE copy to make the change. This way it did not alter the default printer settings. Once the report was closed the DEVMODE copy was deleted from memory.

The logic for CR .NET assemblies now is you set the info within .NET using Windows API's before setting it in CR to use the new printer parameters.

It was easier for CR to push this to Windows Printer Dialog boxes or runtime parameters rather than trying to maintain the custom Printer API's in CR. Printer drivers tended to have issues and Cr had to "hack" a work around or handle specific issues within our code which became a nightmare to maintain. Pushing this to .NET no longer becomes a CR problem, if something doesn't work then discuss with the printer manufacture or the printer driver maker or Microsoft...

Hope that's clear....

Thanks again

Don

Former Member
0 Kudos

Thank you for your help and information - a bit sad that there is no way to preset the prefences for the printer and duplex in the Viewer

My only workaround at the moment is to have the option to view plus an option to print without viewing in duplex

Maybe one day there will be a better solution

Regards

David

0 Kudos

Hi David,

One last quick suggestion. I was talking to Ludek about this and he suggested setting the printer up before loading the report, then setting the report to that printer. See if that resolves the issue.

Thanks again

Don

Former Member
0 Kudos

Hi Don

Thank you for the idea

I had thought of finding out if I could install the same printer twice so that one could be set to Duplex and the other to single and then select the appropriate printer when printing - but I have not had time to explore that idea

Given that VS 2010 is supposed to be better with more ability than the old VB6, I would have thought that Microsoft would have created a class that allowed you to access the printer settings and preferences with greater ease than before rather than making it impossible

I thought that I had not found the method and was searching with the wrong terms ratheer than it could not be done

Thank you for your efforts and sorry for any confusion when I was trying to apply your suggestions in the wrong place

Regards

David

Answers (0)