whycxzp
2024-01-03 66db1d15cf5d4b51a346a42b66f0505bd7f31ce0
src/main/java/com/whyc/util/DwgToPdfUtil.java
@@ -4,9 +4,7 @@
import com.aspose.cad.Image;
import com.aspose.cad.imageoptions.CadRasterizationOptions;
import com.aspose.cad.imageoptions.PdfOptions;
import com.aspose.cad.internal.J.F;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileInputStream;
@@ -15,7 +13,7 @@
@Slf4j
public class DwgToPdfUtil {
    public static File Dwg2Pdf(File dwgFile) throws IOException {
    public static String dwg2Pdf(File dwgFile) throws IOException {
        FileInputStream fileInputStream;
        //将dwg文件转换成InputStream输入流
        fileInputStream = new FileInputStream(dwgFile);
@@ -36,7 +34,7 @@
        pdfOptions.setVectorRasterizationOptions(rasterizationOptions);
        //输出文件
        File outputFile = new File(dwgFile.getName().substring(0,dwgFile.getName().lastIndexOf("."))+".pdf");
        File outputFile = new File(dwgFile.getParent()+File.separator+dwgFile.getName().substring(0,dwgFile.getName().lastIndexOf("."))+"-dwg.pdf");
        //存放地址
        try {
            objImage.save(outputFile.getPath(), pdfOptions);
@@ -46,18 +44,10 @@
        } finally {
            fileInputStream.close();
        }
        log.info("文件转换成功{}",dwgFile.getName());
        return outputFile;
        //log.info("文件转换成功{}",dwgFile.getName());
        return outputFile.getName();
    }
    public static void main(String[] args) throws IOException {
        long l = System.currentTimeMillis();
        File file = new File("C:\\Users\\29550\\Desktop\\当前项目\\202207图纸管理\\IDCE-6006NT(5ST3010+接触器替换5ST3040)(双天线)结构件_A09(2022-7-5)\\IDCE-6006NT(5ST3010+接触器替换5ST3040) PCBA专用结构件BOM表_A08(2022-6-10)\\IDCE2415CT-701(2016-3-8).dwg");
        File file1 = Dwg2Pdf(file);
        System.out.println(file1.getAbsolutePath());
        long l1 = System.currentTimeMillis();
        System.out.println((l1-l)/1000);
    }
}