Hi every body
I am trying to generate PDF from EXCEL .I am using Acrobat Distiller and 
PostScript printer.
I am sending the code in this i am getting the Error
StreamPrintServiceFactory[] factories = 0
Due to which i am unable to do the processing further.
Any suggestion on why this error,and how to solve.
Any suggestion welcome.
Hope to see from any one.

import java.awt.*;
import java.awt.print.*;
import java.awt.geom.*;
import java.io.*;
import java.awt.*;
import javax.print.*;
import javax.print.DocFlavor.INPUT_STREAM;
import java.io.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import java.awt.print.PrinterJob;


 class PrintPStoPDF {

        public static void main(String args[]) {


                DocFlavor flavor =  DocFlavor.INPUT_STREAM.TEXT_PLAIN_US_ASCII;
                //DocFlavor flavor = DocFlavor.BYTE_ARRAY.POSTSCRIPT;
                //DocFlavor flavor = new 
DocFlavor("application/postscript","java.io.InputStream");
                /* Specify the type of the output stream */
                String psMimeType = DocFlavor.BYTE_ARRAY.PDF.getMimeType();
                StreamPrintServiceFactory[] factories = 
StreamPrintServiceFactory.lookupStreamPrintServiceFactories(flavor, psMimeType);
                System.out.println("The factory length is :"+factories.length);
                if (factories.length == 0) {
                        System.err.println("No suitable factories");
                        System.exit(0);
                }
                try {
                        /* Load the file */
                        FileInputStream fis = new FileInputStream("C:/Documents 
and Settings/ost2/Desktop/out.ps");
                        /* Create a file for the exported postscript */
                        String filename = "C:/Documents and 
Settings/ost2/Desktop/nitish.pdf";
                        FileOutputStream fos = new FileOutputStream(filename);
                        /* Create a Stream printer for PDF */
                        StreamPrintService sps = 
factories[0].getPrintService(fos);
                        /* Create and call a Print Job for the PostScript */
                        DocPrintJob pj = sps.createPrintJob();
                        PrintRequestAttributeSet aset = new 
HashPrintRequestAttributeSet();
                        //aset.add(new Copies(2));
                        //aset.add(MediaSizeName.ISO_A4);
                        //aset.add(Sides.TWO_SIDED_LONG_EDGE);
                        //aset.add(Finishings.STAPLE);
                        Doc doc = new SimpleDoc(fis, flavor, null);
                        pj.print(doc, aset);
                        fos.close();

                } catch (PrintException pe) {
                        System.err.println(pe);
                } catch (IOException ie) {
                        System.err.println(ie);
                }
        }
}


Reply via email to