Problem printing an HTML document using javax.print API. Please help!
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Ankur_Das
Posted On:   Monday, January 7, 2002 04:18 AM

I have written the following code: import java.io.*; import javax.print.*; import javax.print.attribute.*; import javax.print.attribute.standard.*; public class PrintTest { public static void main(String args[]) { InputStream psStream = null; try { psStream = new FileInputStream("test.htm"); } catch (FileNotFoundException ffne) { ffne.printStackTrace(); } if (psStream == null) { return; } DocFlavor psInFormat = new DocFlavor("text/html","java.io.InputStream"); Doc myDoc = new SimpleDoc(psStream, psInFormat, null); PrintRequestAttributeSet aset =   More>>

I have written the following code:

import java.io.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;

public class PrintTest
{
public static void main(String args[])
{
InputStream psStream = null;
try
{
psStream = new FileInputStream("test.htm");
} catch (FileNotFoundException ffne)
{
ffne.printStackTrace();
}
if (psStream == null)
{
return;
}
DocFlavor psInFormat = new DocFlavor("text/html","java.io.InputStream");
Doc myDoc = new SimpleDoc(psStream, psInFormat, null);
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(new Copies(2));
aset.add(MediaSizeName.ISO_A4);
aset.add(Sides.ONE_SIDED);
PrintService[] services = PrintServiceLookup.lookupPrintServices(psInFormat, aset);
DocPrintJob job = services[0].createPrintJob();
try {
job.print(myDoc, aset);
} catch (PrintException pe) {pe.printStackTrace();}
}
}

But I am getting the following exception:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at PrintTest.main(PrintTest.java:30)
Press any key to continue . . .

Please help

   <<Less
About | Sitemap | Contact