Solved

Print to PostScript Printer with Crystal Reports Basic in VS 2008

Posted on 2009-05-14
9
1,019 Views
Last Modified: 2012-05-07
Issue: Printing to postscript printer prompts for filename

I am trying to print via .net  to a postscript printer.  However, my version of crystal reports in Visual Studio 2008 does not come with this method...of which others claim to fix the issue?

reportDocument.PrintToPrinter(printerSettings, pageSettings, True) ?

I have checked and there does not exist an overloaded method in the .net object browser for this 'PrintToPrinter' method that would accept PrinterSettings object??

The only method I have is as below:
===============================
public virtual void PrintToPrinter(int nCopies, bool collated, int startPageN, int endPageN)
Member of CrystalDecisions.CrystalReports.Engine.ReportDocument

Summary:
Prints the specified pages of the report to the printer selected using the PrintOptions.PrinterName property. If no printer is selected, the default printer specified in the report will be used.

Parameters:
nCopies: Indicates the number of copies to print.
collated: Indicates whether to collate the pages.
startPageN: Indicates the first page to print.
endPageN: Indicates the last page to print.
===============================
My version is Crystal Reports Basic and is what comes with VS 2008 (not upgraded):

From the GAC:
CrystalDecisions.CrystalReports.Engine, Version=10.5.3700.0
FileVersion: 10.5.0.1943
.NET FRAMEWORK v3.5 SP1

Please help.

Thanks,

EM
string reportpath = Server.MapPath(string.Format(@"Reports\{0}.rpt", reportName));

            ConnectionInfo connectionInfo = SetReportConnection(PageConnection);

            ReportDocument oRpt = new ReportDocument();

            oRpt.Load(reportpath);

            SetDBLogonForReport(connectionInfo, oRpt);

            SetCurrentValuesForParameterField(oRpt, rptParams);

            PrinterSettings printerSettings  = new PrinterSettings();

            PageSettings pageSettings = new PageSettings();

          

           //CopyFrom also does not work !

            oRpt.PrintOptions.CopyTo(printerSettings, pageSettings);

            printerSettings.PrinterName = "Win2PDF";

            printerSettings.PrintFileName = szFileName;

            printerSettings.PrintToFile = true;

//other posts on forums claim that this fixes the issue, but my compiler doesn't recognize

            // and searching object browser does not find any overloaded methods. 

           // oRpt.PrintToPrinter(printerSettings, pageSettings, true);
 

            

           oRpt.PrintToPrinter(1, false, 0, 0);

Open in new window

0
Comment
Question by:RBCLS
  • 4
  • 3
  • 2
9 Comments
 
LVL 34

Expert Comment

by:James0628
ID: 24391635
I don't know that I'll be able to help with your problem, because I don't run reports this way, but I may be able to help get things started by asking for some clarification.

 Are you trying to print to an actual PostScript printer, or to a "virtual" PDF printer?  I assumed that you were referring to a physical printer that used the PostScript language, but then I saw the Win2PDF in your code.

 James
0
 

Author Comment

by:RBCLS
ID: 24395816
Thank you so much for your response and help. Here is the info you requested:
I stand corrected, it is a 'virtual' pdf printer. You are correct in your assumption, it is Win2PDF.  
My goal is to print to a high quality pdf document that is as close as possible to output generated from printing the crystal report directly from the crystal report viewer. The Crystal Reports Export to Pdf does not produce an acceptable level of quality for our print purposes.  It shrinks the font and page regardless of the type of font used or page margins specified. Hence, I have chosen this method of printing the report.
My problem is that regardless of the printer type, I need to specify the filename, but Crystal Reports despite offering an ability to '.CopyFrom' and CopyTo' printer/page settings, it does not seem to pass or even use the PrintFileName property (though other properties are correctly utilized in this method).  When running the application that calls the code, it still prompts for a filename? I have tried printing to XPS Document printer and I get the same problem.  
I just keep thinking..... Why would Crystal offer that functionality and then not utilize it?  I hope that my code is just incorrectly calling or using the wrong properties for the printertoprinter method, as I am now very reluctantly resorting to using a WIN32 API method to print as after talking to management, there is not any other motivation or desire to upgrade to Crystal 2008.  What is more fustrating is that previous versions of Crystal, it was very easy to print to a file, so I am feeling very silly that I can't do this in .NET.
 
EM
0
 
LVL 100

Expert Comment

by:mlmcc
ID: 24396108
That may be the Win2PDF doesn't interface with Crystal properly.  I have printed directly to a file in code and can specify a filename.

You have to set it up before the printtoprinter

mlmcc
0
 

Author Comment

by:RBCLS
ID: 24396637
Dear Mlmcc,
Thank you for your response.
In my code sample, I am specifying the filename and then I call the PrintToPrinterMethod.
From code sample posted:
-------------------------------
printerSettings.PrintToFile = true;
printerSettings.PrintFileName = szFileName;
<.......other code, etc.....>
oRpt.PrintToPrinter(1, false, 0, 0);
 -------------------------------
Can you send me a code sample of how you set the filename?  Also, are you using the basic or upgraded version of Crystal Reports that comes with Visual Studio 2008?
Thanks,
EM
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 100

Expert Comment

by:mlmcc
ID: 24397186
My samples are from earlier versions of Crystal and in VB using the RDC so the code wouldn't apply.

mlmcc
0
 

Author Comment

by:RBCLS
ID: 24397346
Me too! I have a version that works perfectly in VB6 and with the RDC as well that i created a few years ago, hence I feel like a complete idiot that I can't get this working in the basic version of Crystal Reports that comes bundled with VS 2008?  What is more infuriating, is that CR offers an export to PDF functionality that is really subpar in terms of output giving you the allusion that creating pdfs from crystal reports would be somewhat natively supported...but oh how misleading....I am tempted to try a trial version of the upgrade just to see if this works in that version as other forum post users claim, but I have already recieved management directive that purchasing the upgrade is NOT desired.
0
 
LVL 34

Expert Comment

by:James0628
ID: 24400702
Hmm.  I've always thought that the PDF files created by CR's export function looked pretty much perfect, but maybe you just have requirements that I don't have.  It's possible that you're right about it shrinking things and it's just never been an issue here.  

 I wish I could help, but I just don't run reports from code like that.  Just for the heck of it, have you tried a different PDF "printer"?  "CutePDF Writer" is the one that I happen to use, but there are any number of others.

 James
0
 
LVL 100

Accepted Solution

by:
mlmcc earned 250 total points
ID: 24401152
ACcording to his, the .Net versionn doesn't support local printing.
https://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/f08d00a7-951e-2b10-f1a7-a279f68bfba4

mlmcc
0
 

Author Comment

by:RBCLS
ID: 24404407
Thank you MLMCC. This solves my delimma as the documentation from the software clearly states that local printing is NOT supported in my edition of the product. Therefore, we need to Upgrade to Crystal Reports 2008 Professional or use Win32 API or maybe get the .net namespace system.printing to print it (of which my current implementation gives a strange GDI error!)....Anyways, at least I can confirm that the ability to print to file in my edition of Crystal has not been included by the software vendor, so I will not waste any more futile attempts at that method of printing to file. Thank you for your post.
EM
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Crystal Reports: 5 Tests for Top Performance It is complete, your masterpiece report.  Not only does it meet your customer’s expectations, it blows them out the water, all they want is beautifully summarised and displayed in a myriad of ways. …
I hate sub reports and always consider them the last resort in any reporting solution.  The negative effect on performance and maintainability is just not worth the easy ride they give the report writer.  Nine times out of ten reporting requirements…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now