1

我曾使用 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 吗?解释步骤。

4

0 回答 0