新增:PDF文件生成图片的像素大小,dpi 越高,图片质量越清晰,同时也会消耗更多的计算资源。

This commit is contained in:
gaoxiongzaq 2023-04-27 16:27:04 +08:00
parent 65af89d711
commit d18677b9ed
4 changed files with 35 additions and 16 deletions

View File

@ -120,13 +120,13 @@ watermark.angle = ${WATERMARK_ANGLE:10}
#Tif类型图片浏览模式tif利用前端js插件浏览jpg转换为jpg后前端显示pdf转换为pdf后显示便于打印
tif.preview.type = ${KK_TIF_PREVIEW_TYPE:tif}
# 备案信息
BeiAn =
#禁止上传类型
prohibit =exe,dll,dat
#删除密码
sc.password =123456
#删除 转换后OFFICECADTIFF压缩包源文件 默认开启 节约磁盘空间
delete.source.file = true
配置PDF文件生成图片的像素大小dpi 越高图片质量越清晰同时也会消耗更多的计算资源
pdf2jpg.dpi = 105

View File

@ -46,6 +46,7 @@ public class ConfigConstants {
private static String[] prohibit= {};
private static String size;
private static String password;
private static int pdf2JpgDpi;
private static Boolean deletesourcefile;
public static final String DEFAULT_CACHE_ENABLED = "true";
@ -71,6 +72,7 @@ public class ConfigConstants {
public static final String DEFAULT_size_DISABLE = "500MB";
public static final String DEFAULT_prohibit_DISABLE = "exe,dll";
public static final String DEFAULT_password_DISABLE = "123456";
public static final String DEFAULT_PDF2_JPG_DPI_SIZE_DISABLE = "105";
public static final String DEFAULT_Delete_Source_File_PREVIEW_TYPE = "true";
public static Boolean isCacheEnabled() {
@ -408,6 +410,19 @@ public class ConfigConstants {
ConfigConstants.password = password;
}
public static int getpdf2JpgDpi() {
return pdf2JpgDpi;
}
@Value("${pdf.picture.size:105}")
public void pdf2JpgDpi(int pdf2JpgDpi) {
setpdf2JpgDpiValue(pdf2JpgDpi);
}
public static void setpdf2JpgDpiValue(int pdf2JpgDpi) {
ConfigConstants.pdf2JpgDpi = pdf2JpgDpi;
}
public static Boolean getdeletesourcefile() {
return deletesourcefile;
}

View File

@ -58,6 +58,7 @@ public class ConfigRefreshComponent {
String BeiAn;
String size;
String password;
int pdf2JpgDpi;
Boolean deletesourcefile;
while (true) {
FileReader fileReader = new FileReader(configFilePath);
@ -87,6 +88,7 @@ public class ConfigRefreshComponent {
BeiAn = properties.getProperty("BeiAn", ConfigConstants.DEFAULT_BeiAn_DISABLE);
prohibit = properties.getProperty("prohibit", ConfigConstants.DEFAULT_prohibit_DISABLE);
password = properties.getProperty("sc.password", ConfigConstants.DEFAULT_password_DISABLE);
pdf2JpgDpi = Integer.parseInt(properties.getProperty("pdf2jpg.dpi", ConfigConstants.DEFAULT_PDF2_JPG_DPI_SIZE_DISABLE));
deletesourcefile = Boolean.parseBoolean(properties.getProperty("delete.source.file", ConfigConstants.DEFAULT_Delete_Source_File_PREVIEW_TYPE));
prohibitArray = prohibit.split(",");
@ -111,6 +113,7 @@ public class ConfigRefreshComponent {
ConfigConstants.setsizeValue(size);
ConfigConstants.setprohibitValue(prohibitArray);
ConfigConstants.setpasswordValue(password);
ConfigConstants.setpdf2JpgDpiValue(pdf2JpgDpi);
ConfigConstants.setdeletesourcefileValue(deletesourcefile);
setWatermarkConfig(properties);
bufferedReader.close();

View File

@ -8,6 +8,7 @@ import cn.keking.service.cache.NotResourceCache;
import cn.keking.utils.EncodingDetects;
import cn.keking.utils.KkFileUtils;
import cn.keking.utils.WebUtils;
import cn.keking.web.filter.BaseUrlFilter;
import com.aspose.cad.CodePages;
import com.aspose.cad.Color;
import com.aspose.cad.Image;
@ -28,8 +29,6 @@ import org.springframework.util.StringUtils;
import javax.servlet.http.HttpServletRequest;
import java.awt.image.BufferedImage;
import java.io.*;
import java.net.URL;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
@ -248,8 +247,8 @@ public class FileHandlerService {
String imageFilePath;
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
imageFilePath = folder + File.separator + pageIndex + pdf2jpg_image_format;
BufferedImage image = pdfRenderer.renderImageWithDPI(pageIndex, 105, ImageType.RGB);
ImageIOUtil.writeImage(image, imageFilePath, 105);
BufferedImage image = pdfRenderer.renderImageWithDPI(pageIndex, ConfigConstants.getpdf2JpgDpi(), ImageType.RGB);
ImageIOUtil.writeImage(image, imageFilePath, ConfigConstants.getpdf2JpgDpi());
String imageUrl = this.getPdf2jpgUrl(pdfName, pageIndex);
imageUrls.add(imageUrl);
}
@ -298,6 +297,16 @@ public class FileHandlerService {
}
return false;
}
/**
*
* @param str 原字符串待截取原串
* @param posStr 指定字符串
* @return 截取截取指定字符串之后的数据
*/
public static String getSubString(String str, String posStr){
return str.substring(str.indexOf(posStr) + posStr.length());
}
/**
* 获取文件属性
@ -311,14 +320,6 @@ public class FileHandlerService {
FileType type;
String fileName;
String fullFileName = WebUtils.getUrlParameterReg(url, "fullfilename");
String urlStrr = null;
URL urll;
try {
urll = new URL(url);
urlStrr = URLDecoder.decode(urll.getPath(), "UTF-8");
} catch (Exception e) {
}
if (StringUtils.hasText(fullFileName)) {
fileName = fullFileName;
type = FileType.typeFromFileName(fullFileName);