!178 office 功能调整 支持批注 转换页码限制 生成水印等等

Merge pull request !178 from 陈精华/office1
pull/180/head
陈精华 1 year ago committed by Gitee
commit fa2a2b4342
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

@ -142,3 +142,19 @@ pdf2jpg.dpi = ${KK_PDF2JPG_DPI:144}
office.type.web = ${KK_OFFICE_TYPE_WEB:web}
#Cadtifjssvgsvgpdfpdf便
cad.preview.type = ${KK_CAD_PREVIEW_TYPE:pdf}
#OFFICE
# 使 (1-5)
office.pagerange = ${KK_OFFICE_PAGERANGE:false}
# 使 (kkFileView)
office.watermark = ${KK_OFFICE_WATERMARK:false}
#OFFICE JPEG
office.quality = ${KK_OFFICE_QUALITY:80}
#
office.maximageresolution = ${KK_OFFICE_MAXIMAGERESOLUTION:150}
#
office.exportbookmarks = ${KK_OFFICE_EXPORTBOOKMARKS:true}
#PDF
office.exportnotes = ${KK_OFFICE_EXPORTNOTES:true}
# PDF ()
office.documentopenpasswords = ${KK_OFFICE_DOCUMENTOPENPASSWORD:true}

@ -51,6 +51,13 @@ public class ConfigConstants {
private static String cadPreviewType;
private static Boolean deleteSourceFile;
private static Boolean deleteCaptcha;
private static String officePageRange;
private static String officeWatermark;
private static String officeQuality;
private static String officeMaxImageResolution;
private static Boolean officeExportBookmarks;
private static Boolean officeExportNotes;
private static Boolean officeDocumentOpenPasswords;
public static final String DEFAULT_CACHE_ENABLED = "true";
public static final String DEFAULT_TXT_TYPE = "txt,html,htm,asp,jsp,xml,json,properties,md,gitignore,log,java,py,c,cpp,sql,sh,bat,m,bas,prg,cmd";
@ -81,6 +88,15 @@ public class ConfigConstants {
public static final String DEFAULT_DELETE_SOURCE_FILE = "true";
public static final String DEFAULT_DELETE_CAPTCHA = "false";
public static final String DEFAULT_OFFICE_PAQERANQE = "false";
public static final String DEFAULT_OFFICE_WATERMARK = "false";
public static final String DEFAULT_OFFICE_QUALITY = "80";
public static final String DEFAULT_OFFICE_MAXIMAQERESOLUTION = "150";
public static final String DEFAULT_OFFICE_EXPORTBOOKMARKS = "true";
public static final String DEFAULT_OFFICE_EXPORTNOTES = "true";
public static final String DEFAULT_OFFICE_EOCUMENTOPENPASSWORDS = "true";
public static Boolean isCacheEnabled() {
return cacheEnabled;
}
@ -478,4 +494,86 @@ public class ConfigConstants {
public static void setDeleteCaptchaValue(Boolean deleteCaptcha) {
ConfigConstants.deleteCaptcha = deleteCaptcha;
}
/**
* OFFICE
*/
public static String getOfficePageRange() {
return officePageRange;
}
@Value("${office.pagerange:false}")
public void setOfficePageRange(String officePageRange) {
setOfficePageRangeValue(officePageRange);
}
public static void setOfficePageRangeValue(String officePageRange) {
ConfigConstants.officePageRange = officePageRange;
}
public static String getOfficeWatermark() {
return officeWatermark;
}
@Value("${office.watermark:false}")
public void setOfficeWatermark(String officeWatermark) {
setOfficeWatermarkValue(officeWatermark);
}
public static void setOfficeWatermarkValue(String officeWatermark) {
ConfigConstants.officeWatermark = officeWatermark;
}
public static String getOfficeQuality() {
return officeQuality;
}
@Value("${office.quality:80}")
public void setOfficeQuality(String officeQuality) {
setOfficeQualityValue(officeQuality);
}
public static void setOfficeQualityValue(String officeQuality) {
ConfigConstants.officeQuality = officeQuality;
}
public static String getOfficeMaxImageResolution() {
return officeMaxImageResolution;
}
@Value("${office.maximageresolution:150}")
public void setOfficeMaxImageResolution(String officeMaxImageResolution) {
setOfficeMaxImageResolutionValue(officeMaxImageResolution);
}
public static void setOfficeMaxImageResolutionValue(String officeMaxImageResolution) {
ConfigConstants.officeMaxImageResolution = officeMaxImageResolution;
}
public static Boolean getOfficeExportBookmarks() {
return officeExportBookmarks;
}
@Value("${office.exportbookmarks:true}")
public void setOfficeExportBookmarks(Boolean officeExportBookmarks) {
setOfficeExportBookmarksValue(officeExportBookmarks);
}
public static void setOfficeExportBookmarksValue(Boolean officeExportBookmarks) {
ConfigConstants.officeExportBookmarks = officeExportBookmarks;
}
public static Boolean getOfficeExportNotes() {
return officeExportNotes;
}
@Value("${office.exportnotes:true}")
public void setExportNotes(Boolean officeExportNotes) {
setOfficeExportNotesValue(officeExportNotes);
}
public static void setOfficeExportNotesValue(Boolean officeExportNotes) {
ConfigConstants.officeExportNotes = officeExportNotes;
}
public static Boolean getOfficeDocumentOpenPasswords() {
return officeDocumentOpenPasswords;
}
@Value("${office.documentopenpasswords:true}")
public void setDocumentOpenPasswords(Boolean officeDocumentOpenPasswords) {
setOfficeDocumentOpenPasswordsValue(officeDocumentOpenPasswords);
}
public static void setOfficeDocumentOpenPasswordsValue(Boolean officeDocumentOpenPasswords) {
ConfigConstants.officeDocumentOpenPasswords = officeDocumentOpenPasswords;
}
}

@ -63,6 +63,13 @@ public class ConfigRefreshComponent {
String cadPreviewType;
boolean deleteSourceFile;
boolean deleteCaptcha;
String officPageRange;
String officWatermark;
String officQuality;
String officMaxImageResolution;
boolean officExportBookmarks;
boolean officeExportNotes;
boolean officeDocumentOpenPasswords;
while (true) {
FileReader fileReader = new FileReader(configFilePath);
BufferedReader bufferedReader = new BufferedReader(fileReader);
@ -96,6 +103,13 @@ public class ConfigRefreshComponent {
officeTypeWeb = properties.getProperty("office.type.web", ConfigConstants.DEFAULT_OFFICE_TYPE_WEB);
deleteSourceFile = Boolean.parseBoolean(properties.getProperty("delete.source.file", ConfigConstants.DEFAULT_DELETE_SOURCE_FILE));
deleteCaptcha = Boolean.parseBoolean(properties.getProperty("delete.captcha", ConfigConstants.DEFAULT_DELETE_CAPTCHA));
officPageRange = properties.getProperty("office.pagerange", ConfigConstants.DEFAULT_OFFICE_PAQERANQE);
officWatermark = properties.getProperty("office.watermark", ConfigConstants.DEFAULT_OFFICE_WATERMARK);
officQuality = properties.getProperty("office.quality", ConfigConstants.DEFAULT_OFFICE_QUALITY);
officMaxImageResolution = properties.getProperty("office.maximageresolution", ConfigConstants.DEFAULT_OFFICE_MAXIMAQERESOLUTION);
officExportBookmarks = Boolean.parseBoolean(properties.getProperty("office.exportbookmarks", ConfigConstants.DEFAULT_OFFICE_EXPORTBOOKMARKS));
officeExportNotes = Boolean.parseBoolean(properties.getProperty("office.exportnotes", ConfigConstants.DEFAULT_OFFICE_EXPORTNOTES));
officeDocumentOpenPasswords = Boolean.parseBoolean(properties.getProperty("office.documentopenpasswords", ConfigConstants.DEFAULT_OFFICE_EOCUMENTOPENPASSWORDS));
prohibitArray = prohibit.split(",");
ConfigConstants.setCacheEnabledValueValue(cacheEnabled);
@ -122,6 +136,13 @@ public class ConfigRefreshComponent {
ConfigConstants.setPasswordValue(password);
ConfigConstants.setPdf2JpgDpiValue(pdf2JpgDpi);
ConfigConstants.setOfficeTypeWebValue(officeTypeWeb);
ConfigConstants.setOfficePageRangeValue(officPageRange);
ConfigConstants.setOfficeWatermarkValue(officWatermark);
ConfigConstants.setOfficeQualityValue(officQuality);
ConfigConstants.setOfficeMaxImageResolutionValue(officMaxImageResolution);
ConfigConstants.setOfficeExportBookmarksValue(officExportBookmarks);
ConfigConstants.setOfficeExportNotesValue(officeExportNotes);
ConfigConstants.setOfficeDocumentOpenPasswordsValue(officeDocumentOpenPasswords);
ConfigConstants.setDeleteSourceFileValue(deleteSourceFile);
ConfigConstants.setDeleteCaptchaValue(deleteCaptcha);
setWatermarkConfig(properties);

@ -1,5 +1,6 @@
package cn.keking.service;
import cn.keking.config.ConfigConstants;
import cn.keking.model.FileAttribute;
import com.sun.star.document.UpdateDocMode;
import org.apache.commons.lang3.StringUtils;
@ -33,15 +34,36 @@ public class OfficeToPdfService {
logger.error("创建目录【{}】失败,请检查目录权限!",outputFilePath_end);
}
LocalConverter.Builder builder;
Map<String, Object> filterData = new HashMap<>();
filterData.put("EncryptFile", true);
if(!ConfigConstants.getOfficePageRange().equals("false")){
filterData.put("PageRange", ConfigConstants.getOfficePageRange()); //限制页面
}
if(!ConfigConstants.getOfficeWatermark().equals("false")){
filterData.put("Watermark", ConfigConstants.getOfficeWatermark()); //水印
}
filterData.put("Quality", ConfigConstants.getOfficeQuality()); //图片压缩
filterData.put("MaxImageResolution", ConfigConstants.getOfficeMaxImageResolution()); //DPI
if(ConfigConstants.getOfficeExportBookmarks()){
filterData.put("ExportBookmarks", true); //导出书签
}
if(ConfigConstants.getOfficeExportNotes()){
filterData.put("ExportNotes", true); //批注作为PDF的注释
}
if(!ConfigConstants.getOfficeDocumentOpenPasswords()){
filterData.put("DocumentOpenPassword", fileAttribute.getFilePassword()); //给PDF添加密码
}
Map<String, Object> customProperties = new HashMap<>();
customProperties.put("FilterData", filterData);
if (StringUtils.isNotBlank(fileAttribute.getFilePassword())) {
Map<String, Object> loadProperties = new HashMap<>();
loadProperties.put("Hidden", true);
loadProperties.put("ReadOnly", true);
loadProperties.put("UpdateDocMode", UpdateDocMode.NO_UPDATE);
loadProperties.put("Password", fileAttribute.getFilePassword());
builder = LocalConverter.builder().loadProperties(loadProperties);
builder = LocalConverter.builder().loadProperties(loadProperties).storeProperties(customProperties);
} else {
builder = LocalConverter.builder();
builder = LocalConverter.builder().storeProperties(customProperties);
}
builder.build().convert(inputFile).to(outputFile).execute();
}

Loading…
Cancel
Save