2.8K Star 20.5K Fork 8.1K

GVPkeking / kkFileView

 / 详情

可否加CAD图纸 dwg格式的在线预览

已完成
创建于  
2019-09-05 15:45

可否加CAD图纸 dwg格式的在线预览

评论 (5)

yao136 创建了任务

com.aspose.cad jar包 已经实现

@Component
public class DwgConverToPDF {
    /**
     * @param inputFilePath 选择dwg文件路径
     * @param outputFilePath 保存FTP文件路径
     */
    public static boolean openDwgToPDF(String inputFilePath, String outputFilePath) {
        boolean flag = false;
        if (null != inputFilePath) {
            File inputFile = new File(inputFilePath);
            // 判断目标文件路径是否为空
            if (null == outputFilePath) {
                // 转换后的文件路径
                String outputFilePath_end = getOutputFilePath(inputFilePath);
                if (inputFile.exists()) {// 找不到源文件, 则返回
                    converterFile(inputFilePath, outputFilePath_end);
                    flag = true;
                }
            } else {
                if (inputFile.exists()) {// 找不到源文件, 则返回
                    converterFile(inputFilePath, outputFilePath);
                    flag = true;
                }
            }
//            officeManager.stop();
        } else {
            flag = false;
        }
        return flag;
    }

    /**
     * 获取输出文件
     *
     * @param inputFilePath
     * @return
     */
    public static String getOutputFilePath(String inputFilePath) {
        String outputFilePath = inputFilePath.replaceAll("."
                + getPostfix(inputFilePath), ".pdf");
        return outputFilePath;
    }

    /**
     * 转换文件
     * @param inputFilePath
     * @param outputFilePath
     */
    public static void converterFile(String inputFilePath, String outputFilePath) {
        com.aspose.cad.Image cadImage = com.aspose.cad.Image.load(inputFilePath);          //com.aspose.cad.Image
        CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions();
        rasterizationOptions.setLayouts(new String[]{"Model"});
        rasterizationOptions.setNoScaling(true);
        rasterizationOptions.setBackgroundColor(Color.getWhite());
        float width=cadImage.getWidth();
        float height=cadImage.getHeight();
        rasterizationOptions.setPageWidth(width);
        rasterizationOptions.setPageHeight(height);
        rasterizationOptions.setPdfProductLocation("center");
        rasterizationOptions.setAutomaticLayoutsScaling(true);
        rasterizationOptions.setDrawType(CadDrawTypeMode.UseObjectColor);
        // Create an instance of PdfOptions
        PdfOptions pdfOptions = new PdfOptions();
        // Set the VectorRasterizationOptions property
        pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
        // Export the DWG to PDF
        OutputStream stream = null;
        try {
            stream = new FileOutputStream(outputFilePath);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        cadImage.save(stream, pdfOptions);
        cadImage.close();
    }
}
陈精华 负责人设置为陈精华
陈精华 添加了
 
enhancement
标签
陈精华 添加了
 
feature
标签

CAD图预览有问题

输入图片说明代码执行到这里就卡死了

陈精华 任务状态待办的 修改为已完成

com.aspose.cad jar包 ,运行 大cad文件 占用内存 很大

还是不建议做CAD转换,CAD太大,转换失败的。

登录 后才可以发表评论

状态
负责人
里程碑
Pull Requests
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
开始日期   -   截止日期
-
置顶选项
优先级
参与者(2)
1498525 fengdan80 1638585963
Java
1
https://gitee.com/kekingcn/file-online-preview.git
git@gitee.com:kekingcn/file-online-preview.git
kekingcn
file-online-preview
kkFileView

搜索帮助