合并分支

This commit is contained in:
2023-03-04 10:03:22 +08:00
parent a4a0567740
commit 63ca605019
7 changed files with 123 additions and 8 deletions

View File

@@ -46,6 +46,11 @@
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
</dependency>
</dependencies>
</project>

View File

@@ -1,5 +1,6 @@
package com.qn.controller;
import org.apache.http.HttpResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
@@ -8,6 +9,7 @@ import org.springframework.web.bind.annotation.RequestMethod;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
@Controller
public class TestController {
@@ -34,9 +36,10 @@ public class TestController {
/**
* 表白
*/
@RequestMapping(value = "/image", method = RequestMethod.GET)
public void image() throws IOException {
File file = new File("/home/type/job");
@RequestMapping(value = "/pdf", method = RequestMethod.GET)
public void image(HttpServletResponse response) throws IOException {
PrintWriter writer = response.getWriter();
writer.write("如需下载请先付款!");
}
}

View File

@@ -0,0 +1,43 @@
package com.qn.controller.utils;
import org.apache.pdfbox.pdmodel.PDDocument;
import org.apache.pdfbox.rendering.PDFRenderer;
import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
public class PDFUtils {
private static final float DPI = 100;
private static final String IMG_TYPE = "PNG";
public static void pdfToImg(String filePath) throws IOException {
File file = new File(filePath);
if (file.exists()){
PDDocument document = PDDocument.load(file);
PDFRenderer renderer = new PDFRenderer(document);
int numberOfPages = document.getNumberOfPages();
for (int i = 0; i < numberOfPages; i++){
BufferedImage bufferedImage = renderer.renderImageWithDPI(i, DPI);
ByteArrayOutputStream out = new ByteArrayOutputStream();
ImageIO.write(bufferedImage, IMG_TYPE, out);
File imgFile = new File("/Users/limqhz/home/test/pdf/img/" + i + ".png");
FileOutputStream outputStream = new FileOutputStream(imgFile);
outputStream.write(out.toByteArray());
outputStream.close();
out.close();
}
}
}
public static void main(String[] args) throws IOException {
PDFUtils.pdfToImg("/Users/limqhz/Downloads/1.pdf");
}
}