cancel
Showing results for 
Search instead for 
Did you mean: 

different result when print using crystal report viewer and PrintOutputController.PrintReport

Former Member
0 Kudos

Hi.

I'm using VS 2015

and CR v13,SP16

i am using user defined paper 12 x 14 cm,

when print using PrintOutputController.PrintReport the result become smaller than it should be.

when print using CRViewer the result is good and as it should be. but user must set the preferences to user defined paper size and the other printer setting. even though my default setting from control panel has been set.

is there anyways to make it programatically sett all of the properties?


datasource for R is setted with another function.

this is my printing code

                PrintDocument pDoc = new PrintDocument();

                PrinterSettings dPrinterSett = new PrinterSettings();

                PageSettings dPageSetting = new PageSettings();

               

                PrintOptions printOption = R.ReportClientDocument.PrintOutputController.GetPrintOptions();

                printOption.DissociatePageSizeAndPrinterPaperSize = false;

                printOption.PaperSize = CrPaperSizeEnum.crPaperSizeUser;

                printOption.PrinterDuplex = CrPrinterDuplexEnum.crPrinterDuplexSimplex;

                PrintReportOptions printReportOption = new PrintReportOptions();

                printReportOption.PaperSize = CrPaperSizeEnum.crPaperSizeUser;

                printReportOption.Collated = true;

               

                R.ReportClientDocument.PrintOutputController.ModifyPrintOptions(printOption);

                R.ReportClientDocument.PrintOutputController.ModifyPrinterName(dPrinterSett.PrinterName);

                R.ReportClientDocument.PrintOutputController.ModifyUserPaperSize((dPageSetting.PaperSize.Height * 1440/100),                                                                                                                         (dPageSetting.PaperSize.Width * 1440/100));

                if (pDoc.DefaultPageSettings.PaperSize.Height > pDoc.DefaultPageSettings.PaperSize.Width)

                {

                    R.ReportClientDocument.PrintOutputController.ModifyPaperOrientation(CrPaperOrientationEnum.crPaperOrientationPortrait);

                }

                else

                {

                    R.ReportClientDocument.PrintOutputController.ModifyPaperOrientation(CrPaperOrientationEnum.crPaperOrientationLandscape);

                }

               

                R.ReportClientDocument.PrintOutputController.PrintReport(printReportOption);

Any Help is appreciated,

Thankyou..

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Paper size must be defined on the printer before sending to the printer. CR looks for the custom paper size ENUM, if not found it looks for the Custom Paper Size by name, so make sure all of the printers have that paper size created on each PC and using the same Name.

Search for KBA 2163438 and it has a test app to print, see if that works for you.

Don

Answers (1)

Answers (1)

Former Member
0 Kudos

Thankyou so much for your help,

finally the problem has been solved.

all this time i just need the enum number. and because your code it's all clear now

Thanks alot Don.

and this is my code if someone need it.

               PrintDocument pDoc = new PrintDocument();

                PrinterSettings dPrinterSett = new PrinterSettings();

                PageSettings dPageSetting = new PageSettings(dPrinterSett);

                PrintLayoutSettings dPrintLayout = new PrintLayoutSettings();

              

   //set printer name

                dPageSetting.PrinterSettings.PrinterName = dPrinterSett.PrinterName;

             

   //set printer paper size

                int myEnum = getPaperSizeRawKindByName("12x14");

 

  //set Rpt.PrintOption

                R.PrintOptions.PaperSize = (CrystalDecisions.Shared.PaperSize)myEnum;

                R.PrintOptions.PrinterName = pDoc.PrinterSettings.PrinterName;

                R.PrintOptions.DissociatePageSizeAndPrinterPaperSize = true;

   //print

                R.PrintToPrinter(dPrinterSett, dPageSetting, false, dPrintLayout);

function to get the enum(rawKind)

private int getPaperSizeRawKindByName(string name)

{

            PrintDocument pDoc = new PrintDocument();

            int result = -1;

            foreach (System.Drawing.Printing.PaperSize x in pDoc.PrinterSettings.PaperSizes)

            {

                if (x.PaperName == name)

                    result =  x.RawKind;

            }

            return result;

}

Former Member
0 Kudos

Hi All,

I tried to use PrintToPrinter to print report, my code is R.PrintToPrinter(1, False, 0, 0), I found that this method taking long time to print out report compared with the R.ReportClientDocument.PrintOutputController.PrintReport(printReportOption). Do you know the different of the printing speed of R.PrintToPrinter(dPrinterSett, dPageSetting, false, dPrintLayout) and R.PrintToPrinter(1, False, 0, 0)?

I also tried to use R.ReportClientDocument.PrintOutputController.PrintReport(printReportOption) to print out report with Thermal Printer, but sometimes it got issue.

Issue 1: Printer will feed extra paper before printing.

Issue 2: The crystal report is printed in a very small size.

There are the same printer use to design crystal report and print report.

Your advice and suggestion is very appreciated.

0 Kudos

Hi Wai,

Are you using Remote Desktop Communicator?

Did you use my test app attached to KBA 2163438?

Don

Former Member
0 Kudos

Hi Don,

Sorry late to reply. I'm not using Remote Desktop Communicator.

Yes, i tried with the test app KBA 2163438 and solved my problem. I have to set the Printer as default printer first before printing, so, the crystal report printed with normal size and have not feed extra paper before printing.


I have another question, the crystal report is design with Width 8.01cm and Height 399.99cm, but use printer which only support Width 6.35cm and Height 327.61cm. My problem is the words after width 6.35cm is not printed.

How to auto adjust the width and suite the size to print crystal report with Width 6.35cm?


Your help is very appreciated.


Thank you.

0 Kudos

Hi Wai,

Great that test app showed you how to to fix the problem.

As for fitting the report on a smaller page than it was designed for you could set the output to PDF or export the report to PDF, do this in code and then print to PDF and set the Page property to fit page.

That should auto-sale the page to fit smaller than designed.

CR cannot do this for you.

Don

Former Member
0 Kudos

Hi Don,

Thanks for your reply. It got solved my existing problem, but it make another issue come out, sometimes the printing part is very slow. Sometimes the crystal report printing part taking around 10 seconds and sometimes the printing part make the program become not responding. Can you advise me how to fix this problem?

below is my sample code:

Dim rptClientDoc As CrystalDecisions.ReportAppServer.ClientDoc.ISCDReportClientDocument

Dim pDoc As New System.Drawing.Printing.PrintDocument

Dim rasPROpts As New CrystalDecisions.ReportAppServer.Controllers.PrintReportOptions

Dim PrintLayout As New CrystalDecisions.Shared.PrintLayoutSettings()

Dim RASPO As New CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions

pDoc.PrinterSettings.PrinterName = zPrinterName

zReportDoc.PrintOptions.PrinterName = zPrinterName

zReportDoc.PrintOptions.PaperSize = pDoc.PrinterSettings.DefaultPageSettings.PaperSize.RawKind

zReportDoc.PrintOptions.PaperSource = pDoc.PrinterSettings.DefaultPageSettings.PaperSource.RawKind

PrintLayout.Scaling = PrintLayoutSettings.PrintScaling.DoNotScale

Dim newOpts As New CrystalDecisions.ReportAppServer.ReportDefModel.PrintOptions()

newOpts.PrinterName = zPrinterName

newOpts.DriverName = "winspool"

newOpts.DissociatePageSizeAndPrinterPaperSize = False

newOpts.PaperSize = pDoc.PrinterSettings.DefaultPageSettings.PaperSize.RawKind

newOpts.PaperSource = pDoc.PrinterSettings.DefaultPageSettings.PaperSource.RawKind

rptClientDoc.PrintOutputController.ModifyPageMargins(0, 0, 0, 0)

rptClientDoc.PrintOutputController.ModifyPrintOptions(newOpts)

rasPROpts.PrinterName = zPrinterName

rasPROpts.PaperSize = pDoc.PrinterSettings.DefaultPageSettings.PaperSize.RawKind

rasPROpts.PaperSource = pDoc.PrinterSettings.DefaultPageSettings.PaperSource.RawKind

rptClientDoc.PrintOutputController.ModifyPaperOrientation(CrystalDecisions.ReportAppServer.ReportDefModel.CrPaperOrientationEnum.crPaperOrientationPortrait)

Dim MyRptName As String = zReportDoc.FileName.ToString()

MyRptName = MyRptName.Substring(MyRptName.LastIndexOf("\") + 1, (zReportDoc.FileName.Length - 3) - (MyRptName.LastIndexOf("\") + 2))

rasPROpts.JobTitle = MyRptName

rptClientDoc.PrintOutputController.PrintReport(rasPROpts)

0 Kudos

Hi Wai,

Can you start a new thread, this one was resolved.

Check your printer driver and spooler or check you report, use a report with saved data, that way it doesn't hit the DB which could slow things down.

Thanks

Don