Pana 5j
Verwijderd
Google is je vriend:
http://www.google.com/search?hl=en&ie=UTF8&oe=UTF8&q=java+graphics+printing
en dan is misschien dit wel tot hulp?
http://java.sun.com/products/java-media/2D/forDevelopers/sdk12print.html
http://www.google.com/search?hl=en&ie=UTF8&oe=UTF8&q=java+graphics+printing
en dan is misschien dit wel tot hulp?
http://java.sun.com/products/java-media/2D/forDevelopers/sdk12print.html
Dat had ik ook gevonden maar ik kom niet helemaal uit. Ik moet een gif plaatje uitprinten en ik kan het zo niet vinden.
Toch bedank voor je reactie.
Toch bedank voor je reactie.
Pana 5j
kijk wat ik vond
code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
| Example: PrintGIF.java
/*
* Copyright 2001 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the proprietary information of Sun Microsystems, Inc.
* Use is subject to license terms.
*
*/
import java.io.*;
import javax.print.*;
import javax.print.attribute.*;
import javax.print.attribute.standard.*;
/*
* Use the Java(TM) Print Service API to locate a print service which
* can print a GIF-encoded image. A GIF image is printed according to
* a job template specified as a set of printing attributes.
*/
public class PrintGIF {
public static void main(String args[]) {
/* Use the pre-defined flavor for a GIF from an InputStream */
DocFlavor flavor = DocFlavor.INPUT_STREAM.GIF;
/* Create a set which specifies how the job is to be printed */
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
aset.add(MediaSizeName.NA_LETTER);
aset.add(new Copies(1));
/* Locate print services which can print a GIF in the manner specified */
PrintService[] pservices =
PrintServiceLookup.lookupPrintServices(flavor, aset);
if (pservices.length > 0) {
/* Create a Print Job */
DocPrintJob printJob = pservices[0].createPrintJob();
/* Create a Doc implementation to pass the print data */
Doc doc = new InputStreamDoc("java2dlogo.gif", flavor);
/* Print the doc as specified */
try {
printJob.print(doc, aset);
} catch (PrintException e) {
System.err.println(e);
}
} else {
System.err.println("No suitable printers");
}
}
}
class InputStreamDoc implements Doc {
private String filename;
private DocFlavor docFlavor;
private InputStream stream;
public InputStreamDoc(String name, DocFlavor flavor) {
filename = name;
docFlavor = flavor;
}
public DocFlavor getDocFlavor() {
return docFlavor;
}
/* No attributes attached to this Doc - mainly useful for MultiDoc */
public DocAttributeSet getAttributes() {
return null;
}
/* Since the data is to be supplied as an InputStream delegate to
* getStreamForBytes().
*/
public Object getPrintData() throws IOException {
return getStreamForBytes();
}
/* Not possible to return a GIF as text */
public Reader getReaderForText()
throws UnsupportedEncodingException, IOException {
return null;
}
/* Return the print data as an InputStream.
* Always return the same instance.
*/
public InputStream getStreamForBytes() throws IOException {
synchronized(this) {
if (stream == null) {
stream = new FileInputStream(filename);
}
return stream;
}
}
} |