Post Author: tsparg
CA Forum: JAVA
Hi allI downloaded this code from the business objects website, and then played around with it. Have got it to print, but could somebody tell me how i would export using similiar code?Am i on the right track, or do i need to do an about face? import com.businessobjects.crystalreports.printer.bean.ReportPrinter;import com.crystaldecisions.reports.sdk.ReportClientDocument;import com.crystaldecisions.sdk.occa.report.document.PaperSize;import com.crystaldecisions.sdk.occa.report.document.PaperSource;import com.crystaldecisions.sdk.occa.report.document.PrintReportOptions;import com.crystaldecisions.sdk.occa.report.lib.ReportSDKExceptionBase;import com.microsoft.sqlserver.jdbc.SQLServerConnection;import com.microsoft.sqlserver.jdbc.SQLServerResultSet;import java.sql.DriverManager;import java.sql.SQLException;import java.util.logging.Level;import java.util.logging.Logger;import javax.print.PrintService;import javax.print.PrintServiceLookup;/** * Applies to: XI Release 2. * Date Created: October 2005. * Description: This sample demonstrates how to print a report directly to a printer (server-side printing). * NOTE: If the report is based on a secured database the database login credentials * will need to be set before calling the export method below. Also, if the report * has parameters, then values will need to be set for the report before export method can * be called or an error will be thrown. See the ViewReportParameters or ViewReportLogon samples * for samples on how to set parameters and login credentials through the JRC SDK. * Author: CW. *///Crystal Java Reporting Component (JRC) imports.public class JRCPrintReport { static final String REPORT_NAME = "JRCPrintReport.rpt"; public static void main(String[] args) { if (args.length == 0) { PrintService[] printers = PrintServiceLookup.lookupPrintServices(null, null); System.out.println("Available printers : "); for (int i = 0; i < printers.length; i++) { System.out.println(printers[i].getName()); } System.out.println("end Available printers "); System.exit(0); } try { //Open report. ReportClientDocument reportClientDoc = new ReportClientDocument(); reportClientDoc.open(REPORT_NAME, 0); //Create and set print options. PrintReportOptions printOptions = new PrintReportOptions(); printOptions.setPrinterName(args[1]); printOptions.setJobTitle("Sample Print Job from JRC."); printOptions.setPaperSource(PaperSource.auto); printOptions.setPaperSize(PaperSize.paperLetter); printOptions.setNumberOfCopies(1); printOptions.setCollated(false); PrintReportOptions.PageRange printPageRange = new PrintReportOptions.PageRange(1, 1); printOptions.addPrinterPageRange(printPageRange); ReportPrinter repPrint; repPrint = new ReportPrinter(); repPrint.setReportSource(reportClientDoc.getReportSource()); repPrint.print(printOptions); reportClientDoc.close(); System.out.println("Successfully sent report to the printer."); } catch (ReportSDKExceptionBase ex) { Logger.getLogger("global").log(java.util.logging.Level.SEVERE, null, ex); } }} regardsTim