Print Page | Close Window

How to Print to File in CR for .NET (VB.NET 2005)

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Writing Code
Forum Discription: .NET programming API, report integration
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=844
Printed Date: 05 May 2024 at 2:21am


Topic: How to Print to File in CR for .NET (VB.NET 2005)
Posted By: N11689
Subject: How to Print to File in CR for .NET (VB.NET 2005)
Date Posted: 13 Jun 2007 at 8:32am
We are upgrading our VB6 application to VB.NET(2005).  We are switching from the RDC to using Crystal Reports for .NET assemblies.
 
In VB6 (RDC) we used to be able to use the PrintOutEx Method to print a report to a file.  I cannot locate how to do this in VB.NET(2005) using the Crystal Reports for .NET assemblies.
 
What we are trying to accomplish is sending the report to a printer that has a PostScript print driver, and the end result is to print to a file.  So, the report will end up as a file in PostScript format that we will then fax via our faxserver.
 
The ExportToDisk method does not work for us as it required you to export to a specific format, none of which are postscript.  So, we really need to know how to print to a file.
 
Please help.  Thank you.



Replies:
Posted By: BrianBischof
Date Posted: 13 Jun 2007 at 8:40am
I don't have it off the top of my head. But something like PrintToPrinter() is what you're looking for I think.

-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: N11689
Date Posted: 13 Jun 2007 at 10:50am
PrintToPrinter only allows the arguments (Copies, Collated, StartPage, EndPage).  The PrintOutEx method had the arguments of (PromptUser, Copies, Collated, StartPage, StopPage, PrintFileName).
 
Any other suggestions


Posted By: BrianBischof
Date Posted: 13 Jun 2007 at 11:01am
Ahh. Yes. The RDC has much more functionality built into it. I don't know of another option then. Sorry.

-------------
Please support the forum! Tell others by linking to it on your blog or website:<a href="http://www.crystalreportsbook.com/forum/">Crystal Reports Forum</a>


Posted By: hilfy
Date Posted: 13 Jun 2007 at 3:31pm
Is there a problem with just installing the printer driver for the postscript printer and then printing directly to it?  That should handle the formatting you need without having to send the report to a file first.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: N11689
Date Posted: 14 Jun 2007 at 4:56am

We distribute our application to many customers.  Our application provides the ability to fax certain reports.  The fax software our customers use require the file to be faxed be in a postscript format.  Therefore, we print the Crystal Report to a file using the postscript print driver.  The fax software will then search its directory for any postscript files and fax them.  Therefore, we cannot print directly to the postscript printer, we must print to a file.

Thanks.


Posted By: hilfy
Date Posted: 14 Jun 2007 at 7:17am
Ok, now I understand.  Thanks for the info!
 
A quick search of the knowledgebase doesn't show anything more recent than 2001, so that's not a help.  You may have to open a support case with Business Objects to see if this is even possible with the new SDK.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics


Posted By: N11689
Date Posted: 02 Aug 2007 at 12:55pm
I opened an incident with Business Objects.  They said there is not a way to do what we want to do with the Crystal Reports for .NET assemblies.  They are going to implement a way to create a postscript file and include it in Service Pack 3 of Crystal XI Release 2.  They would not say how the postscript will be created (ie, ExportToDisk or any other method), only that they would include it in CRXI Release 2 SP3 which they intend to release sometime this coming winter.


Posted By: Hridya
Date Posted: 12 Nov 2007 at 12:59am

I also have similar problem..... Please let me know if you found any solution to this.....

 
 
Thanks in advance
 


Posted By: N11689
Date Posted: 25 Apr 2008 at 6:02am
Just an update...this has been fixed in Crystal XI Release 2 Service Pack 3.
I just finished testing, and it now allows you to print to a file without prompting the user.  We are now able to create a postscript file.
 
 


Posted By: 123CAW
Date Posted: 11 Jun 2008 at 10:02am

Could you please show me your logic that was used to create the postscript file using VB 2005? I am just getting started with Crystal XI would like to see your method of creating the postscript file using VB (without prompting the user).

Thanks.



Posted By: N11689
Date Posted: 12 Jun 2008 at 6:08am
In Summary, we declare the following objects:

Public objPrinterSettings As New System.Drawing.Printing.PrinterSettings

Public objPageSettings As New System.Drawing.Printing.PageSettings

Public objReportDocument As New CrystalDecisions.CrystalReports.Engine.ReportDocument
 
 
We set the objPrinterSettings.PrinterName to our postscript printer (a printer with a postscript driver):

objPrinterSettings.PrinterName = postscriptprintername

We then set the objPageSettings.PrinterName to the objPrinterSettings.PrinterName

objPageSettings.PrinterSettings.PrinterName = objPrinterSettings.PrinterName

Our application creates the .PS filename:  PostScriptFilename.ps
 
Then we print to the printer

objPrinterSettings.PrintToFile = True

objPrinterSettings.PrintFileName = PostScriptFilename.ps
 
We use the load method to load the crystal report into the objReportDocument object
 
We then process each report (set parameter values, logon tables, etc.) and the finally 'print' the report to the printer using the following command:

objReportDocument.PrintToPrinter(objPrinterSettings, objPageSettings, False)

 


Posted By: Hridya
Date Posted: 12 Jun 2008 at 7:04am

hi,

r u using any third party tool to create a .ps file? If no, please let me know how u r doing that.


Posted By: N11689
Date Posted: 12 Jun 2008 at 7:19am
No.  We create a filename with a .PS extension.  When the report 'prints' to a file, we send it to a printer defined with a PostScript print driver (specifically Digital LN03R ScriptPrinter).  Therefore, when the file is created, it has a .PS extension and is the driver formats it into the postscript format.


Posted By: 123CAW
Date Posted: 14 Jul 2008 at 9:38am
Hi N11689. Thank you for the code sample. However, I still have a problem.
 
 
I know that I have Crystal XI Release 2 installed but I cannot say for sure that I have SP3 installed. When I start Crystal, and go to 'Help, About' it does not show if SP3 has been applied. All it shows is the version number. Are you using version 11.5.9.1076? I installed it from a file called 'crxir2_sp3' but I was expecting to see the SP level when I go to the about screen.
 
I am able to use your code up to a certain point. I get an error on the following line.
 
objReportDocument.PrintToPrinter(objPrinterSettings, objPageSettings, False).
 
The error states that the arguments for 'PrintToPrinter' are invalid. It is expecting an integer where I have 'objPrinterSettings' and 'objPageSettings'.
 
Am I missing something?
 
Thanks for you help.


Posted By: kuphaus
Date Posted: 05 Sep 2008 at 7:03am
I too am getting the same problem with

objReportDocument.PrintToPrinter(objPrinterSettings, objPageSettings, False).
 
The error states that the arguments for 'PrintToPrinter' are invalid. It is expecting an integer where I have 'objPrinterSettings' and 'objPageSettings'.
 
Can someone lead me in the right direction to get this to work?
Thanks,
Kelli


Posted By: wjzabs
Date Posted: 16 Mar 2009 at 7:57pm
I am not sure how you finally got it to work - I was able to get a report to be printed to a file with the following code:
 
Dim prtdoc As New System.Drawing.Printing.PrintDocument
Dim prset As System.Drawing.Printing.PrinterSettings = prtdoc.PrinterSettings
prset.PrinterName = "Your Windows Printer Name"
prset.PrintToFile = True
prset.PrintFileName = "report.tmp"
CrystalReport.PrintToPrinter(prset, New System.Drawing.Printing.PageSettings, False)
 
Note that the Print to File option has nothing to do with Crystal - it is an option offered by the Windows Print dialog (which is why I had to use the PrinterSettings object, and not a Crystal-derived object).
 
If you are going to send the output to a windows socket (IP & Port), make sure that the Windows PrinterName that you choose has the printer driver matching the printer that you expect to eventually send the output to.
 
To do this, you would read the file that you just created into a byte array and then send that array to the socket, which is useful if you want to print to a printer knowing it's IP and port, without having to create a Windows (spooled) printer.  Crystal has an ExportToStream method, but this does not capture the Printer Specific codes and escape sequences needed to interact with the printer - this is the purpose of the Printer Driver.
 
Bad things will happen if the destination printer does not know how to interpret the control codes which resulted from the printer driver your Windows PrinterName is associated with.


Posted By: uda_shy
Date Posted: 28 Jul 2010 at 6:12pm
hi everyone,
    This is maybe out of the topic, but do you know where can I save the RPT file as PDF (smaller MB not the same as the default) using it IDE? coz when I save it as PDF, it did treat the RPT file as Image so that's why the MB quite big.


Need help how to reconfigured the Crystal Report IDE if thier's any..


Thanks.. uda


Posted By: hilfy
Date Posted: 29 Jul 2010 at 12:37am
There is no way to do this.  The export .dll files that Crystal uses provide access to a very limited set of features for each type of export.  You can't access anything beyond the options that are available to you in the export screens in the Crystal IDE.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics



Print Page | Close Window