|
@@ -0,0 +1,75 @@
|
|
|
+package com.ebei.device.asset.weixin.contorller;
|
|
|
+
|
|
|
+import com.ebei.device.asset.weixin.util.HttpRequestUtils;
|
|
|
+import com.ebei.device.asset.weixin.util.ResponseEx;
|
|
|
+import io.swagger.annotations.Api;
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.http.HttpResponse;
|
|
|
+import org.apache.pdfbox.pdmodel.PDDocument;
|
|
|
+import org.apache.pdfbox.rendering.PDFRenderer;
|
|
|
+import org.springframework.util.Base64Utils;
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
+import org.springframework.web.bind.annotation.PostMapping;
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
+
|
|
|
+import javax.imageio.ImageIO;
|
|
|
+import java.awt.image.BufferedImage;
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.FileOutputStream;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+/**
|
|
|
+ * @ClassName : AssetRectifyController
|
|
|
+ * @Description : 整改对应 前端控制器
|
|
|
+ * @Date : 2021-04-12 18:33
|
|
|
+ */
|
|
|
+
|
|
|
+@RestController
|
|
|
+@RequestMapping("/assetRectify")
|
|
|
+@Api(value = "assetRectify" , description = "整改相关接口")
|
|
|
+@Slf4j
|
|
|
+public class AssetRectifyController {
|
|
|
+
|
|
|
+
|
|
|
+ @ApiOperation(value="获取pdf转换为图片list")
|
|
|
+ @PostMapping("/getPdfToImage/{taskId}")
|
|
|
+ public ResponseEx<Object> getPdfToImage(@PathVariable Long taskId ) throws Exception {
|
|
|
+
|
|
|
+ InputStream inputStream = HttpRequestUtils.getUrlConnection("http://101.200.225.123/device/assetApp/createHardwareWebPDF/"+taskId+"?preView=true", 1024*1024).getInputStream();
|
|
|
+ PDDocument pdDocument = PDDocument.load(inputStream);
|
|
|
+ int pageCount = pdDocument.getNumberOfPages();
|
|
|
+ PDFRenderer pdfRenderer = new PDFRenderer(pdDocument);
|
|
|
+
|
|
|
+ List<Map<String, Object>> resultinfo = new ArrayList<Map<String, Object>>();
|
|
|
+ Map<String, Object> obj = null;
|
|
|
+ for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
|
|
|
+ // BufferedImage imageb = pdfRenderer.renderImageWithDPI(pageIndex, 105, ImageType.RGB);
|
|
|
+ // 第二个参数数字越大越清晰
|
|
|
+ BufferedImage bufferedImage = null;
|
|
|
+ try {
|
|
|
+ bufferedImage = pdfRenderer.renderImageWithDPI(pageIndex, 150);
|
|
|
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
|
+ ImageIO.write(bufferedImage, "jpg", outputStream);// 写入流
|
|
|
+// FileOutputStream fileOutputStream = null;
|
|
|
+// fileOutputStream = new FileOutputStream("c:\\usr\\imgeTest\\"+System.currentTimeMillis()+".jpg");
|
|
|
+// fileOutputStream.write(outputStream.toByteArray());
|
|
|
+ obj = new HashMap<String, Object>();
|
|
|
+ obj.put("index", pageIndex);
|
|
|
+ obj.put("pic", Base64Utils.encodeToString(outputStream.toByteArray()));
|
|
|
+ resultinfo.add(obj);
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ pdDocument.close();
|
|
|
+ return ResponseEx.createSuccess(resultinfo);
|
|
|
+ }
|
|
|
+
|
|
|
+}
|