Re: Using SimpleDoc() with DocFlavour String (not InputStream)
- From: Ian Wilson <scobloke2@xxxxxxxxxxxxx>
- Date: Thu, 28 Sep 2006 17:00:48 +0100
Ian Wilson wrote:
When trying to use SimpleDoc I get this error:
Exception in thread "main" java.lang.IllegalArgumentException: data is not of declared type
at javax.print.SimpleDoc.<init>(Unknown Source)
at PrintPsString.main(PrintPsString.java:32)
No doubt because I am specifying a DocFlavour of INPUT_STREAM (DocFlavor.INPUT_STREAM.POSTSCRIPT) and supplying a String.
I managed to make it work by converting the String to a byte array and using a suitable DocFlavor (the BYTE_ARRAY DocFlavours are the only other family that include .POSTSCRIPT)
StringBuffer sb;
...
sb.append("%!PS\n"); // immutable String would be bad
...
String s = sb.toString(); // as no StringBuffer.getBytes()
byte[] ba = s.getBytes();
DocFlavour flavor = DocFlavor.BYTE_ARRAY.POSTSCRIPT;
Doc doc = new SimpleDoc(ba, flavor, null);
...
Is there a way of doing this with fewer intermediary variables and type conversions?
.
- References:
- Using SimpleDoc() with DocFlavour String (not InputStream)
- From: Ian Wilson
- Using SimpleDoc() with DocFlavour String (not InputStream)
- Prev by Date: Using SimpleDoc() with DocFlavour String (not InputStream)
- Next by Date: Re: A "How would you do this"-type of question. not Java-specific.
- Previous by thread: Using SimpleDoc() with DocFlavour String (not InputStream)
- Index(es):