  | |  | Printing problem | Printing problem 2004-01-07 - By nitish kumar sinha
Back <P> Hi every body<BR> I am trying to generate PDF from EXCEL .I am using Acrobat Distiller and PostScript printer.<BR> I am sending the code in this i am getting the Error<BR> StreamPrintServiceFactory[] factories = 0<BR> Due to which i am unable to do the processing further.<BR> Any suggestion on why this error,and how to solve.<BR> Any suggestion welcome.<BR> Hope to see from any one.<BR> <BR> import java.awt.*;<BR> import java.awt.print.*;<BR> import java.awt.geom.*;<BR> import java.io.*;<BR> import java.awt.*;<BR> import javax.print.*;<BR> import javax.print.DocFlavor ;<BR> import java.io.*;<BR> import javax.print.*;<BR> import javax.print.attribute.*;<BR> import javax.print.attribute.standard.*;<BR> import java.awt.print.PrinterJob ;<BR> <BR> <BR> class PrintPStoPDF {<BR> <BR> public static void main(String args[]) {<BR> <BR> <BR> DocFlavor flavor = DocFlavor .INPUT_STREAM.TEXT_PLAIN_US_ASCII;<BR> //DocFlavor flavor = DocFlavor.BYTE _ARRAY.POSTSCRIPT;<BR> //DocFlavor flavor = new DocFlavor( "application/postscript","java.io.InputStream ");<BR> /* Specify the type of the output stream */<BR> String psMimeType = DocFlavor.BYTE _ARRAY.PDF.getMimeType();<BR> StreamPrintServiceFactory[] factories = StreamPrintServiceFactory.lookupStreamPrintServiceFactories (flavor, psMimeType);<BR> System.out.println("The factory length is :"+factories.length);<BR> if (factories.length == 0) {<BR> System.err.println( "No suitable factories");<BR> System.exit(0);<BR> }<BR> try {<BR> /* Load the file */ <BR> FileInputStream fis = new FileInputStream("C:/Documents and Settings/ost2/Desktop/out.ps" );<BR> /* Create a file for the exported postscript */<BR> String filename = "C:/Documents and Settings/ost2/Desktop/nitish.pdf";<BR> FileOutputStream fos = new FileOutputStream(filename);<BR> /* Create a Stream printer for PDF */<BR> StreamPrintService sps = factories[0].getPrintService(fos);<BR> /* Create and call a Print Job for the PostScript */<BR> DocPrintJob pj = sps.createPrintJob();<BR>   ;PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();<BR> //aset.add(new Copies(2));<BR> //aset.add (MediaSizeName.ISO_A4);<BR> //aset.add(Sides .TWO_SIDED_LONG_EDGE);<BR> //aset.add (Finishings.STAPLE);<BR> Doc doc = new SimpleDoc(fis, flavor, null);<BR> pj.print(doc, aset) ;<BR> fos.close();<BR> <BR> } catch (PrintException pe) {<BR> System.err.println (pe);<BR> } catch (IOException ie) {<BR> System.err.println (ie);<BR> }<BR> }<BR> }<BR>
</P>
<br><br> <A target="_blank" HREF="http://clients.rediff.com/signature/track_sig.asp"> <IMG SRC="http://ads.rediff.com/RealMedia/ads/adstream_nx.cgi/www.rediffmail.com /inbox.htm@(protected)" BORDER=0 VSPACE=0 HSPACE=0 HEIGHT=74 WIDTH=496></a>
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 ; 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); } } }
Earn $52 per hosting referral at Lunarpages.
|
|
 |