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