Solved

Print to PostScript Printer with Crystal Reports Basic in VS 2008

Posted on 2009-05-14
9
1,042 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
9 Comments
 
LVL 35

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 101

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
Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

 

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
 
LVL 101

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 35

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 101

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

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…
Hot fix for .Net Crystal Reports 10.2.3600.0 to fix problems with sub reports running on 64 bit operating systems ISSUE: Reports which contain subreports fail with error "Missing Parameter Value" DEPLOYMENT SERVER OS: Windows 2008 with 64 bi…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…

695 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