mirror of
https://gitee.com/kekingcn/file-online-preview.git
synced 2025-04-05 17:37:49 +08:00
!130 新增:PDF文件生成图片的像素大小,dpi 越高,图片质量越清晰,同时也会消耗更多的计算资源。
Merge pull request !130 from 高雄/master
This commit is contained in:
commit
a59abd179f
@ -120,13 +120,13 @@ watermark.angle = ${WATERMARK_ANGLE:10}
|
|||||||
|
|
||||||
#Tif类型图片浏览模式:tif(利用前端js插件浏览);jpg(转换为jpg后前端显示);pdf(转换为pdf后显示,便于打印)
|
#Tif类型图片浏览模式:tif(利用前端js插件浏览);jpg(转换为jpg后前端显示);pdf(转换为pdf后显示,便于打印)
|
||||||
tif.preview.type = ${KK_TIF_PREVIEW_TYPE:tif}
|
tif.preview.type = ${KK_TIF_PREVIEW_TYPE:tif}
|
||||||
|
|
||||||
# 备案信息
|
# 备案信息
|
||||||
BeiAn =
|
BeiAn =
|
||||||
#禁止上传类型
|
#禁止上传类型
|
||||||
prohibit =exe,dll,dat
|
prohibit =exe,dll,dat
|
||||||
#删除密码
|
#删除密码
|
||||||
sc.password =123456
|
sc.password =123456
|
||||||
|
#删除 转换后OFFICE、CAD、TIFF、压缩包源文件 默认开启 节约磁盘空间
|
||||||
#删除 转换后OFFICE、CAD、TIFF、压缩包源文件 默认开启 节约磁盘空间
|
|
||||||
delete.source.file = true
|
delete.source.file = true
|
||||||
|
配置PDF文件生成图片的像素大小,dpi 越高,图片质量越清晰,同时也会消耗更多的计算资源。
|
||||||
|
pdf2jpg.dpi = 105
|
||||||
|
@ -46,6 +46,7 @@ public class ConfigConstants {
|
|||||||
private static String[] prohibit= {};
|
private static String[] prohibit= {};
|
||||||
private static String size;
|
private static String size;
|
||||||
private static String password;
|
private static String password;
|
||||||
|
private static int pdf2JpgDpi;
|
||||||
private static Boolean deletesourcefile;
|
private static Boolean deletesourcefile;
|
||||||
|
|
||||||
public static final String DEFAULT_CACHE_ENABLED = "true";
|
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_size_DISABLE = "500MB";
|
||||||
public static final String DEFAULT_prohibit_DISABLE = "exe,dll";
|
public static final String DEFAULT_prohibit_DISABLE = "exe,dll";
|
||||||
public static final String DEFAULT_password_DISABLE = "123456";
|
public static final String DEFAULT_password_DISABLE = "123456";
|
||||||
|
public static final String DEFAULT_PDF2_JPG_DPI_DISABLE = "105";
|
||||||
public static final String DEFAULT_Delete_Source_File_PREVIEW_TYPE = "true";
|
public static final String DEFAULT_Delete_Source_File_PREVIEW_TYPE = "true";
|
||||||
|
|
||||||
public static Boolean isCacheEnabled() {
|
public static Boolean isCacheEnabled() {
|
||||||
@ -408,6 +410,19 @@ public class ConfigConstants {
|
|||||||
ConfigConstants.password = password;
|
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() {
|
public static Boolean getdeletesourcefile() {
|
||||||
return deletesourcefile;
|
return deletesourcefile;
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,7 @@ public class ConfigRefreshComponent {
|
|||||||
String BeiAn;
|
String BeiAn;
|
||||||
String size;
|
String size;
|
||||||
String password;
|
String password;
|
||||||
|
int pdf2JpgDpi;
|
||||||
Boolean deletesourcefile;
|
Boolean deletesourcefile;
|
||||||
while (true) {
|
while (true) {
|
||||||
FileReader fileReader = new FileReader(configFilePath);
|
FileReader fileReader = new FileReader(configFilePath);
|
||||||
@ -87,6 +88,7 @@ public class ConfigRefreshComponent {
|
|||||||
BeiAn = properties.getProperty("BeiAn", ConfigConstants.DEFAULT_BeiAn_DISABLE);
|
BeiAn = properties.getProperty("BeiAn", ConfigConstants.DEFAULT_BeiAn_DISABLE);
|
||||||
prohibit = properties.getProperty("prohibit", ConfigConstants.DEFAULT_prohibit_DISABLE);
|
prohibit = properties.getProperty("prohibit", ConfigConstants.DEFAULT_prohibit_DISABLE);
|
||||||
password = properties.getProperty("sc.password", ConfigConstants.DEFAULT_password_DISABLE);
|
password = properties.getProperty("sc.password", ConfigConstants.DEFAULT_password_DISABLE);
|
||||||
|
pdf2JpgDpi = Integer.parseInt(properties.getProperty("pdf2jpg.dpi", ConfigConstants.DEFAULT_PDF2_JPG_DPI_DISABLE));
|
||||||
deletesourcefile = Boolean.parseBoolean(properties.getProperty("delete.source.file", ConfigConstants.DEFAULT_Delete_Source_File_PREVIEW_TYPE));
|
deletesourcefile = Boolean.parseBoolean(properties.getProperty("delete.source.file", ConfigConstants.DEFAULT_Delete_Source_File_PREVIEW_TYPE));
|
||||||
prohibitArray = prohibit.split(",");
|
prohibitArray = prohibit.split(",");
|
||||||
|
|
||||||
@ -111,6 +113,7 @@ public class ConfigRefreshComponent {
|
|||||||
ConfigConstants.setsizeValue(size);
|
ConfigConstants.setsizeValue(size);
|
||||||
ConfigConstants.setprohibitValue(prohibitArray);
|
ConfigConstants.setprohibitValue(prohibitArray);
|
||||||
ConfigConstants.setpasswordValue(password);
|
ConfigConstants.setpasswordValue(password);
|
||||||
|
ConfigConstants.setpdf2JpgDpiValue(pdf2JpgDpi);
|
||||||
ConfigConstants.setdeletesourcefileValue(deletesourcefile);
|
ConfigConstants.setdeletesourcefileValue(deletesourcefile);
|
||||||
setWatermarkConfig(properties);
|
setWatermarkConfig(properties);
|
||||||
bufferedReader.close();
|
bufferedReader.close();
|
||||||
|
@ -8,6 +8,7 @@ import cn.keking.service.cache.NotResourceCache;
|
|||||||
import cn.keking.utils.EncodingDetects;
|
import cn.keking.utils.EncodingDetects;
|
||||||
import cn.keking.utils.KkFileUtils;
|
import cn.keking.utils.KkFileUtils;
|
||||||
import cn.keking.utils.WebUtils;
|
import cn.keking.utils.WebUtils;
|
||||||
|
import cn.keking.web.filter.BaseUrlFilter;
|
||||||
import com.aspose.cad.CodePages;
|
import com.aspose.cad.CodePages;
|
||||||
import com.aspose.cad.Color;
|
import com.aspose.cad.Color;
|
||||||
import com.aspose.cad.Image;
|
import com.aspose.cad.Image;
|
||||||
@ -28,8 +29,6 @@ import org.springframework.util.StringUtils;
|
|||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.net.URL;
|
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
@ -248,8 +247,8 @@ public class FileHandlerService {
|
|||||||
String imageFilePath;
|
String imageFilePath;
|
||||||
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
|
for (int pageIndex = 0; pageIndex < pageCount; pageIndex++) {
|
||||||
imageFilePath = folder + File.separator + pageIndex + pdf2jpg_image_format;
|
imageFilePath = folder + File.separator + pageIndex + pdf2jpg_image_format;
|
||||||
BufferedImage image = pdfRenderer.renderImageWithDPI(pageIndex, 105, ImageType.RGB);
|
BufferedImage image = pdfRenderer.renderImageWithDPI(pageIndex, ConfigConstants.getpdf2JpgDpi(), ImageType.RGB);
|
||||||
ImageIOUtil.writeImage(image, imageFilePath, 105);
|
ImageIOUtil.writeImage(image, imageFilePath, ConfigConstants.getpdf2JpgDpi());
|
||||||
String imageUrl = this.getPdf2jpgUrl(pdfName, pageIndex);
|
String imageUrl = this.getPdf2jpgUrl(pdfName, pageIndex);
|
||||||
imageUrls.add(imageUrl);
|
imageUrls.add(imageUrl);
|
||||||
}
|
}
|
||||||
@ -298,6 +297,16 @@ public class FileHandlerService {
|
|||||||
}
|
}
|
||||||
return false;
|
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;
|
FileType type;
|
||||||
String fileName;
|
String fileName;
|
||||||
String fullFileName = WebUtils.getUrlParameterReg(url, "fullfilename");
|
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)) {
|
if (StringUtils.hasText(fullFileName)) {
|
||||||
fileName = fullFileName;
|
fileName = fullFileName;
|
||||||
type = FileType.typeFromFileName(fullFileName);
|
type = FileType.typeFromFileName(fullFileName);
|
||||||
|
Loading…
Reference in New Issue
Block a user