|
@@ -1,16 +1,10 @@
|
|
|
package org.springblade.archive.service.impl;
|
|
|
|
|
|
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
|
|
|
-import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
-import com.itextpdf.text.Element;
|
|
|
-import com.itextpdf.text.pdf.*;
|
|
|
import lombok.AllArgsConstructor;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
-import org.apache.pdfbox.pdmodel.PDDocument;
|
|
|
-import org.apache.pdfbox.pdmodel.PDPage;
|
|
|
-import org.apache.pdfbox.pdmodel.common.PDRectangle;
|
|
|
import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.util.IOUtils;
|
|
|
import org.springblade.archive.entity.ArchiveFormulaConfig;
|
|
@@ -21,6 +15,7 @@ import org.springblade.archive.service.IArchiveFormulaConfigService;
|
|
|
import org.springblade.archive.service.IArchiveProjectConfigService;
|
|
|
import org.springblade.archive.utils.FileUtils;
|
|
|
import org.springblade.archive.utils.FormulaUtil;
|
|
|
+import org.springblade.archive.utils.PdfResizeTool;
|
|
|
import org.springblade.business.entity.ArchiveFile;
|
|
|
import org.springblade.business.feign.ArchiveFileClient;
|
|
|
import org.springblade.common.constant.CommonConstant;
|
|
@@ -30,7 +25,6 @@ import org.springblade.common.utils.SnowFlakeUtil;
|
|
|
import org.springblade.common.vo.DataVO;
|
|
|
import org.springblade.common.vo.FileSize;
|
|
|
import org.springblade.core.oss.model.BladeFile;
|
|
|
-import org.springblade.core.secure.utils.AuthUtil;
|
|
|
import org.springblade.core.tool.utils.ObjectUtil;
|
|
|
import org.springblade.core.tool.utils.ResourceUtil;
|
|
|
import org.springblade.core.tool.utils.StringUtil;
|
|
@@ -38,9 +32,10 @@ import org.springblade.resource.feign.NewIOSSClient;
|
|
|
import org.springblade.system.cache.ParamCache;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
+import java.io.InputStream;
|
|
|
+import java.io.OutputStream;
|
|
|
|
|
|
import java.io.*;
|
|
|
-import java.net.URLEncoder;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.ArrayList;
|
|
@@ -908,36 +903,18 @@ public class ArchiveAutoPdfServiceImpl implements IArchiveAutoPdfService {
|
|
|
OutputStream outputStream = new FileOutputStream(localPdf);
|
|
|
outputStream.write(bytes);
|
|
|
|
|
|
- //将PDF设置为A4纸大小
|
|
|
- this.setPdfToA4Size(localPdf, localPdf);
|
|
|
+ //设置PDF每页大小为A4,内容等比缩放,方向同步
|
|
|
+ PdfResizeTool.resizeToA4WithContentScaling(localPdf, localPdf);
|
|
|
|
|
|
//上传到OSS
|
|
|
String absoluteFileName = FileUtils.getOssPath(OssConstant.ARCHIVE_DIRECTORY, fileName, projectId);
|
|
|
BladeFile file = newIOSSClient.uploadFile(absoluteFileName, localPdf);
|
|
|
url = file.getLink();
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- return url;
|
|
|
- }
|
|
|
|
|
|
- /**
|
|
|
- * 设置pdf大小默认为A4纸大小
|
|
|
- *
|
|
|
- * @param inputPdfPath
|
|
|
- * @param outputPdfPath
|
|
|
- */
|
|
|
- private void setPdfToA4Size(String inputPdfPath, String outputPdfPath) {
|
|
|
- try {
|
|
|
- PDDocument document = PDDocument.load(new File(inputPdfPath));
|
|
|
- PDPage newPage = new PDPage(PDRectangle.A4);
|
|
|
- document.removePage(0);
|
|
|
- document.addPage(newPage);
|
|
|
- document.save(outputPdfPath);
|
|
|
- document.close();
|
|
|
} catch (Exception e) {
|
|
|
e.printStackTrace();
|
|
|
}
|
|
|
+ return url;
|
|
|
}
|
|
|
|
|
|
|