• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1068
  • Last Modified:

Print to PostScript Printer with Crystal Reports Basic in VS 2008

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
RBCLS
Asked:
RBCLS
  • 4
  • 3
  • 2
1 Solution
 
James0628Commented:
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
 
RBCLSAuthor Commented:
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
 
mlmccCommented:
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
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
RBCLSAuthor Commented:
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
 
mlmccCommented:
My samples are from earlier versions of Crystal and in VB using the RDC so the code wouldn't apply.

mlmcc
0
 
RBCLSAuthor Commented:
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
 
James0628Commented:
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
 
mlmccCommented:
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
 
RBCLSAuthor Commented:
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

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now