| | |
| | | @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); |
| | |
| | | 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); |
| | |
| | | fileInputStream.close(); |
| | | } |
| | | log.info("文件转换成功{}",dwgFile.getName()); |
| | | return outputFile; |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | |