本方法是通过引入aspose-cad工具来把dwg转换为svg, aspose-cad的下载地址为: /artifact/com.aspose/aspose-cad, 我是通过本地测试来转换的, 可以成功转换File file = new File("G:/cad");File[] files = file.listFiles();for (File file1 : files) {String path = file1.getAbsolutePath();String name = file1.getName().replace(".dwg", "");Image cadImage = Image.load(path);CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();rasterizationOptions.setAutomaticLayoutsScaling(true);rasterizationOptions.setNoScaling (false);rasterizationOptions.setContentAsBitmap(true);rasterizationOptions.setLayouts(new String[] {"Model"});SvgOptions svgOptions = new SvgOptions();rasterizationOptions.getGraphicsOptions().setSmoothingMode(SmoothingMode.HighQuality);rasterizationOptions.getGraphicsOptions().setTextRenderingHint(TextRenderingHint.AntiAliasGridFit);rasterizationOptions.getGraphicsOptions().setInterpolationMode(InterpolationMode.HighQualityBicubic);int width = cadImage.getWidth();int height = cadImage.getHeight();float zoom = 2.5f;rasterizationOptions.setPageHeight(height * zoom);rasterizationOptions.setPageWidth(width * zoom);rasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor);svgOptions.setVectorRasterizationOptions(rasterizationOptions);cadImage.save("G:/output/" + name +".svg", svgOptions);}
1500字范文,内容丰富有趣,写作好帮手!