package test;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import org.junit.Test;
import org.kabeja.batik.tools.SAXPDFSerializer;
import org.kabeja.dxf.DXFDocument;
import org.kabeja.parser.Parser;
import org.kabeja.parser.ParserBuilder;
import org.kabeja.svg.SVGGenerator;
import org.kabeja.xml.SAXGenerator;
import org.kabeja.xml.SAXSerializer;
/**
* DXF转PDF
* @author HengHui.Wang
*
*/
public class CAD2PDF {
private static void parseFile(String sourceFile, String index)
throws Exception {
InputStream in = new FileInputStream("D:\\"+sourceFile);
// Parser dxfParser = DXFParserBuilder.createDefaultParser();
Parser dxfParser = ParserBuilder.createDefaultParser();
dxfParser.parse(in, "UTF-8");
DXFDocument doc = dxfParser.getDocument();
sourceFile = sourceFile.substring(sourceFile.lastIndexOf(".")+1);
System.out.println("sourceFile is == "+sourceFile);
SAXGenerator generator = new SVGGenerator();
//生成PDF
//SAXSerializer out = new SAXPDFSerializer();
SAXSerializer out = null;
if(sourceFile.equals("dxf")){
out = new SAXPDFSerializer();
}
String outputFile = "D:\\";
OutputStream fileo = new FileOutputStream(outputFile +index+".pdf");
//输出
out.setOutput(fileo);
//生成文件
generator.generate(doc, out, new HashMap());
}
@Test
public void test() throws Exception{
CAD2PDF.parseFile("aaaaaa.dxf", "9-26№12.5D高压离心风机");
}
}
评论5
最新资源