Mailing List
Home
Forum Home
Maven - Project building tool
Axis - Java SOAP implementation
Cocoon - MVC web framework based on XML/XSL
Lucene - Full-featured text search engine APIs
Log4J - A log library
Fop - Create PDF, PCL, PS, SVG, XML driven by XSL formatting objects.
POI - Java Excel, Word and other Microsoft Office files manipulating library
Oracle database error code ...
Subjects
log4j warning: No appenders could be found
java security AccessControlException: access denied (java io FilePermission clie
java lang InstantiationException: org apache tools ant Main
Apache Axis Tutorial
Struts <logic iterate >
log4j properties How to parse outpu to multiple files
configuring log4j with BEA Weblogic 8 1
How to use XSL FOP Java together
JSP precompile
Servlet File Download dialog problem (IE6,Adobe 6 0)
Proposal: Adding jar manifest classpath in jar and war plugins
Unsupported major minor version 48 0 problem while running the an
   telope task
java security AccessControlException: access denied (java io FilePermission
axis wsdl2java Ant Task usage
net sf hibernate MappingException: Error reading resource: test/User hbm xml
Building EAR ANT Script for websphere 5 0
CREATING WAR Files
jsp data into Excel
Classpath problem
Jboss 3 2 3+ vs Tomcat Axis Question
RE: How to include jars and add them into the MANIFEST MF/Class Path
attribute
Printing problem
InstantiationException
Couldn 't find trusted certificate
Please : How can one install ant 1 6 0 under Eclipse 2 1 ?
Excel: Too many different cell formats
Running junit tests fails
XDoclet, Struts and Maven: Where to start? SOLUTION
1 3 final: now giving me java io FileNotFoundException (Too many
open files)
AXIS: tomcat timeout ?
 
Search:  
Power your search with and, or, +, -, or "some phrase" operators.
Printing problem

Printing problem

2004-01-07       - By nitish kumar sinha

 Back
Reply:     1     2  

<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 Source code of 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 Source code of java.awt.print.PrinterJob;<BR>
<BR>
<BR>
class PrintPStoPDF {<BR>
<BR>
&nbsp; &nbsp; &nbsp;public static void main(String args[]) {<BR>
<BR>
<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;DocFlavor flavor =&nbsp; DocFlavor
.INPUT_STREAM.TEXT_PLAIN_US_ASCII;<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;//DocFlavor flavor = DocFlavor.BYTE
_ARRAY.POSTSCRIPT;<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;//DocFlavor flavor = new DocFlavor(
&quot;application/postscript&quot;,&quot;java.io.InputStream Source code of java.io.InputStream&quot;);<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;/* Specify the type of the output
stream */<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;String psMimeType = DocFlavor.BYTE
_ARRAY.PDF.getMimeType();<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;StreamPrintServiceFactory[] factories =
&nbsp; &nbsp; &nbsp;StreamPrintServiceFactory.lookupStreamPrintServiceFactories
(flavor, psMimeType);<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;System.out.println(&quot;The factory
length is :&quot;+factories.length);<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;if (factories.length == 0) {<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;System.err.println(
&quot;No suitable factories&quot;);<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;System.exit(0);<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;}<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;try {<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;/* Load the file */
<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;FileInputStream fis
= new FileInputStream(&quot;C:/Documents and Settings/ost2/Desktop/out.ps&quot;
);<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;/* Create a file
for the exported postscript */<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;String filename =
&quot;C:/Documents and Settings/ost2/Desktop/nitish.pdf&quot;;<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;FileOutputStream
fos = new FileOutputStream(filename);<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;/* Create a Stream
printer for PDF */<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;StreamPrintService
sps = factories[0].getPrintService(fos);<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;/* Create and call
a Print Job for the PostScript */<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;DocPrintJob pj =
sps.createPrintJob();<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp
;PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;//aset.add(new
Copies(2));<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;//aset.add
(MediaSizeName.ISO_A4);<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;//aset.add(Sides
.TWO_SIDED_LONG_EDGE);<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;//aset.add
(Finishings.STAPLE);<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;Doc doc = new
SimpleDoc(fis, flavor, null);<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;pj.print(doc, aset)
;<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;fos.close();<BR>
<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;} catch (PrintException pe) {<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;System.err.println
(pe);<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;} catch (IOException ie) {<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;System.err.println
(ie);<BR>
&nbsp; &nbsp; &nbsp;&nbsp; &nbsp; &nbsp;}<BR>
&nbsp; &nbsp; &nbsp;}<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 Source code of javax.print.DocFlavor;
import java.io.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
import java.awt.print.PrinterJob Source code of 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.