PDF转图片方法细节修改
This commit is contained in:
@@ -5,6 +5,7 @@ import com.lowagie.text.Font;
|
|||||||
import com.lowagie.text.Image;
|
import com.lowagie.text.Image;
|
||||||
import com.lowagie.text.Paragraph;
|
import com.lowagie.text.Paragraph;
|
||||||
import com.lowagie.text.pdf.*;
|
import com.lowagie.text.pdf.*;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.icepdf.core.exceptions.PDFException;
|
import org.icepdf.core.exceptions.PDFException;
|
||||||
import org.icepdf.core.exceptions.PDFSecurityException;
|
import org.icepdf.core.exceptions.PDFSecurityException;
|
||||||
import org.icepdf.core.pobjects.Page;
|
import org.icepdf.core.pobjects.Page;
|
||||||
@@ -19,6 +20,7 @@ import java.io.*;
|
|||||||
/**
|
/**
|
||||||
* 使用 OpenPDF 封装的 pdf 工具类
|
* 使用 OpenPDF 封装的 pdf 工具类
|
||||||
*/
|
*/
|
||||||
|
@Slf4j
|
||||||
public class PDFUtils {
|
public class PDFUtils {
|
||||||
|
|
||||||
private static final int[] A4Size = {595, 842};
|
private static final int[] A4Size = {595, 842};
|
||||||
@@ -145,20 +147,16 @@ public class PDFUtils {
|
|||||||
GraphicsRenderingHints.SCREEN, Page.BOUNDARY_CROPBOX,
|
GraphicsRenderingHints.SCREEN, Page.BOUNDARY_CROPBOX,
|
||||||
rotation, scale);
|
rotation, scale);
|
||||||
RenderedImage rendImage = image;
|
RenderedImage rendImage = image;
|
||||||
try {
|
ImageIO.write(rendImage, "png", outputStream);
|
||||||
ImageIO.write(rendImage, "png", outputStream);
|
//例子中是pdf转png格式的,也可以将上面两行改成jpg,转出jpg格式的,
|
||||||
//例子中是pdf转png格式的,也可以将上面两行改成jpg,转出jpg格式的,
|
//但是从转换效果来看png的清晰度会相对较高。有个小技巧是第一行行改成jpg,
|
||||||
//但是从转换效果来看png的清晰度会相对较高。有个小技巧是第一行行改成jpg,
|
//但第二行使用png,也就是转换成jpg格式但有png清晰度的图片。
|
||||||
//但第二行使用png,也就是转换成jpg格式但有png清晰度的图片。
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
image.flush();
|
image.flush();
|
||||||
document.dispose();
|
document.dispose();
|
||||||
return outputStream;
|
return outputStream;
|
||||||
}
|
}
|
||||||
} catch (PDFException | PDFSecurityException | IOException e1) {
|
} catch (PDFException | IOException | PDFSecurityException e) {
|
||||||
e1.printStackTrace();
|
log.error("PDF转图片异常, e{}", e.getMessage());
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
outputStream.close();
|
outputStream.close();
|
||||||
|
|||||||
Reference in New Issue
Block a user