我曾使用FOP服务将文件格式转换为.afb文件。 (以下代码)
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.sax.SAXResult;
import javax.xml.transform.stream.StreamSource;
import org.apache.fop.apps.MimeConstants;
import org.apache.fop.apps.FOPException;
import org.apache.fop.apps.Fop;
import org.apache.fop.apps.FopFactory;
public class FopService
{
public FopService() throws FOPException, TransformerException, IOException
{
FopFactory fopFactory = FopFactory.newInstance();
OutputStream out = new BufferedOutputStream(new FileOutputStream(new File("E/myfile.X")));
try{
Fop fop = fopFactory.newFop(MimeConstants.MIME_FOP_IF, out);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer(); // identity transformer
Source src = new StreamSource(new File("E/ResultAFP.afp"));
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
}
finally {
//Clean-up
out.close();
}
}
}
现在我需要在打印机上打印这个.afp文件。任何java api都可以吗?解释步骤。