生成通过函件PDF转图片(还有部分排版问题)

This commit is contained in:
pserimal
2023-06-16 19:11:08 +08:00
parent 13a89de2b6
commit 6733deeba8
5 changed files with 52 additions and 47 deletions

View File

@@ -22,6 +22,8 @@ import org.springframework.transaction.annotation.Transactional;
import java.io.*;
import static com.cool.store.utils.PDFUtils.pdf2Img;
@Service
public class PartnerInterviewServiceImpl implements PartnerInterviewService {
@@ -122,19 +124,15 @@ public class PartnerInterviewServiceImpl implements PartnerInterviewService {
String code = passLetterDetail.getPassCode() == null ? PassLetterUtils.genPassCode(createTime) : passLetterDetail.getPassCode();
//生成的 pdf 通过函内存输出流
ByteArrayOutputStream pdfOut = PassLetterUtils.genPassLetter(passLetterDetail.getPartnerName(), code, passLetterDetail.getVerifyCity(), createTime);
FileOutputStream fileOutputStream = new FileOutputStream("passLetter.pdf");
fileOutputStream.write(pdfOut.toByteArray());
fileOutputStream.close();
//生成的 pdf 通过函内存输入流
ByteArrayInputStream inputStream = new ByteArrayInputStream(pdfOut.toByteArray());
// String passPdfUrl = ossServer.uploadFileServer(inputStream, "partner/passLetter/" + code + ".pdf");
String passPdfUrl = "";
String passPdfUrl = ossServer.uploadFileServer(inputStream, "partner/passLetter/" + code + ".pdf");
//转换为图片
inputStream.reset();
ByteArrayOutputStream imageOut = PDFUtils.pdf2Img(inputStream, 2.0f);
inputStream = new ByteArrayInputStream(imageOut.toByteArray());
//上传 OSS
// String passImageUrl = ossServer.uploadFileServer(inputStream, "partner/passLetter/" + code + ".jpg");
String passImageUrl = "";
String passImageUrl = ossServer.uploadFileServer(inputStream, "partner/passLetter/" + code + ".png");
//计算有效期截止日期
DateTime expiryDate = DateUtil.offsetDay(createTime, 60);
String expiryDateStr = DateUtil.format(expiryDate, "yyyy-MM-dd") + " 23:59:59";