New file |
| | |
| | | package com.whyc.util; |
| | | |
| | | import com.aspose.cad.Color; |
| | | 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; |
| | | import java.io.IOException; |
| | | |
| | | @Slf4j |
| | | public class DwgToPdfUtil { |
| | | |
| | | public static File Dwg2Pdf(File dwgFile) throws IOException { |
| | | FileInputStream fileInputStream; |
| | | //将dwg文件转换成InputStream输入流 |
| | | fileInputStream = new FileInputStream(dwgFile); |
| | | |
| | | Image objImage = Image.load(fileInputStream); |
| | | |
| | | CadRasterizationOptions rasterizationOptions = new CadRasterizationOptions(); |
| | | |
| | | //设置颜色 |
| | | rasterizationOptions.setBackgroundColor(Color.getBlack()); |
| | | rasterizationOptions.setPageWidth(1400); |
| | | rasterizationOptions.setPageHeight(650); |
| | | rasterizationOptions.setAutomaticLayoutsScaling(true); |
| | | rasterizationOptions.setNoScaling (false); |
| | | rasterizationOptions.setDrawType(1); |
| | | |
| | | PdfOptions pdfOptions = new PdfOptions(); |
| | | pdfOptions.setVectorRasterizationOptions(rasterizationOptions); |
| | | |
| | | //输出文件 |
| | | File outputFile = new File(dwgFile.getName().substring(0,dwgFile.getName().lastIndexOf("."))+".pdf"); |
| | | //存放地址 |
| | | try { |
| | | objImage.save(outputFile.getPath(), pdfOptions); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | log.error("dwg转pdf失败{}",dwgFile.getName()); |
| | | } finally { |
| | | fileInputStream.close(); |
| | | } |
| | | log.info("文件转换成功{}",dwgFile.getName()); |
| | | return outputFile; |
| | | } |
| | | |
| | | 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); |
| | | } |
| | | } |
| | | |
| | | |