简体   繁体   English

Java:使用Ycad / Kabeja或任何其他类似的库来解析dxf文件

[英]Java: parse dxf file using Ycad / Kabeja or any other simmilar library

I'm pretty new to programming so any help would be much appreciated. 我是编程的新手,所以将不胜感激。

I'm trying to parse a .dxf file in order to get the coordinates of the entities and plot them to a JPanel. 我正在尝试解析.dxf文件,以获取实体的坐标并将其绘制到JPanel。 Basically I would need a graphical presentation of the dxf file. 基本上,我需要dxf文件的图形表示。

So far I've only found some examples on how to use Ycad or Kabeja library but it's still not clear to me how to get the entities or even how the libraries work. 到目前为止,我只找到了一些有关如何使用Ycad或Kabeja库的示例,但我仍然不清楚如何获取实体,甚至库是如何工作的。 It also seems like that the libraries aren't complete because some classes are missing and practically every example code I used had some problems with missing classes. 似乎库还不完整,因为缺少某些类,并且实际上我使用的每个示例代码在缺少类方面都有一些问题。

Also old questions on SO don't give me many answers. 同样,关于SO的旧问题也没有给我很多答案。 If anybody has any experience with the libraries mentioned above or any other method that would help me to resolve my problem, it would be greatly appreciated. 如果有人对上述库或任何其他可帮助我解决问题的方法有任何经验,将不胜感激。

Use kabeja library, it converts DXF to PDF/SVG/JPEG Working example : 使用kabeja库,它将DXF转换为PDF / SVG / JPEG工作示例:

    private static void parseFile(String sourceFile, String index)
        throws FileNotFoundException, ParseException, SAXException {

    InputStream in = new FileInputStream("C:\\Users\\z003kebe\\Downloads\\DWGAndDxf\\dwg\\"+sourceFile);
    // Parser dxfParser = DXFParserBuilder.createDefaultParser();
    Parser dxfParser = ParserBuilder.createDefaultParser();
    dxfParser.parse(new FileInputStream("C:\\Users\\z003kebe\\Downloads\\DWGAndDxf\\dwg\\"+sourceFile), "UTF-8");
    DXFDocument doc = dxfParser.getDocument();

    SAXGenerator generator = new SVGGenerator();

    // generate into outputstream

    // output the SVG
    SAXSerializer out = new SAXPDFSerializer();
    // or you can use also pdf
    // org.kabeja.xml.SAXSerialzer out =
    // org.kabeja.batik.tools.SAXPDFSerializer();
    // tiff
    // org.kabeja.xml.SAXSerialzer out =
    // org.kabeja.batik.tools.SAXTIFFSerializer();
    // png
    // org.kabeja.xml.SAXSerialzer out =
    // org.kabeja.batik.tools.SAXPNGSerializer();
    // jpg
    // org.kabeja.xml.SAXSerialzer out =
    // org.kabeja.batik.tools.SAXJEPGSerializer();

    OutputStream fileo = new FileOutputStream(outputFile+index+".PDF");
    // out.setOutputStream(response.getOutputStream()) //write direct to
    // ServletResponse
    out.setOutput(fileo);
    // generate
    generator.generate(doc, out, new HashMap());

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM