對於java的打印問題
Interface包括 Printable
PrinterJob:初始化打印操作
PageFormat:描述可打印區
public double getImageableX();
public double getImageableY();
public double getImageableWidth();
public double getImageableHeight();
package jinicup
import java
import java
import java
import javax
import javax
import javax
import java
/**********************************
* Implemenation of the printer service
***********************************/
public class PrinterImpl extends JPanel
implements Printable {
private Image image;
private PrinterJob printJob;
private double x
private int imagew
PrinterImpl () {
printJob = PrinterJob
printJob
printJob
}
public int print (Graphics graphics
System
if (pageIndex >=
return Printable
}
x = pageFormat
y = pageFormat
w = pageFormat
h = pageFormat
if(imagew >= imageh){
h=w*imageh/imagew;
}else{
w=h*imagew/imageh;
}
System
System
drawGraphics(graphics);
return Printable
}
public void paint (Graphics graphics) {
drawGraphics(graphics);
}
private void drawGraphics (Graphics graphics) {
graphics
// graphics
}
/**********************************
* starts the printing
* @param byteArrayOfJPEGFile a valid byte array of a jpg file (can be directly from the camera)
***********************************/
public void printByteArray (byte[] byteArrayOfJPEGFile) {
// Toolkit tool = Toolkit
// image=tool
image = (new ImageIcon(byteArrayOfJPEGFile))
imagew=image
imageh=image
System
System
try {
System
printJob
System
} catch (Exception ex) {
System
}
return;
}
/**********************************
* main method
* @param args no args are used
***********************************/
public static void main (String[] args) {
PrinterImpl pi = new PrinterImpl();
try {
FileInputStream fs = new FileInputStream(
System
byte[] array = new byte[fs
fs
pi
} catch (Exception e) {
System
}
}
}
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19135.html