语音转录

This commit is contained in:
hejinbo
2023-11-29 21:16:38 +08:00
parent 7c665da605
commit 07d80398ae
2 changed files with 25 additions and 22 deletions
@@ -4,40 +4,56 @@ import com.documents4j.api.DocumentType;
import com.documents4j.api.IConverter;
import com.documents4j.job.LocalConverter;
import com.itextpdf.text.Document;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.tool.xml.XMLWorkerFontProvider;
import com.itextpdf.tool.xml.XMLWorkerHelper;
import com.ruoyi.common.config.RuoYiConfig;
import com.tencentcloudapi.teo.v20220901.models.CC;
import lombok.extern.slf4j.Slf4j;
import java.io.*;
import java.nio.charset.Charset;
import java.nio.file.Files;
import static cn.hutool.core.util.ClassLoaderUtil.getClassLoader;
/**
* @author wangqiong
* @description pdf转换工具类
* @date 2023-11-28 15:20
*/
@Slf4j
public class PdfUtils {
/**
* 将html字符串转为pdf
* @param pdfFilePath 保存的路径
* @param htmlcontent:必须是完整的html格式,比如<html><body>123</body></html>
*/
public static boolean htmlStringConvertToPDF(String pdfFilePath, String htmlcontent) {
public boolean htmlStringConvertToPDF(String pdfFilePath, String htmlcontent) {
Document document = new Document();
PdfWriter writer = null;
try {
if(!new File(pdfFilePath).exists()){
new File(pdfFilePath).createNewFile();
}
// if(!new File(pdfFilePath).exists()){
// new File(pdfFilePath).createNewFile();
// }
writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFilePath));
// 设置底部距离60,解决重叠问题
document.setPageSize(PageSize.A4);
document.setMargins(50, 45, 50, 60);
document.setMarginMirroring(false);
document.open();
XMLWorkerHelper.getInstance().parseXHtml(writer, document, new ByteArrayInputStream(htmlcontent.getBytes("UTF-8")), null, Charset.forName("UTF-8"));
// 解决PDF中文不显示
String fontPath = "/D:/simsun.ttf"; //字体文件路径
XMLWorkerFontProvider provider = new XMLWorkerFontProvider(XMLWorkerFontProvider.DONTLOOKFORFONTS);
provider.register(fontPath);//注册字体
log.error("注册字体");
XMLWorkerHelper.getInstance().parseXHtml(writer, document, new ByteArrayInputStream(htmlcontent.getBytes("UTF-8")), Charset.forName("UTF-8"), provider);
} catch (Exception e) {
log.error("htmlStringConvertToPDF error", e.getMessage());
return false;
} finally {
if (null != document) {
@@ -131,18 +147,4 @@ public class PdfUtils {
return true;
}
public static void main(String [] args) {
try {
String pdfFile = "D:\\test13.pdf";
String htmlContent1 = "<h1>夫士大夫士大夫发</h1><p>会见韩国机构行家</p ><h2>地方鬼地方鬼地方三个广泛的</h2>";
String htmlContent = "<html><body style=\"font-size:12.0pt; font-family:宋体\">" + "<h1>夫士大夫士大夫发</h1><p>会见韩国机构行家</p ><h2>地方鬼地方鬼地方三个广泛的</h2></body></html>";
String htmlContent2 = "<html><body style=\\\"font-size:12.0pt; font-family:宋体\\\"><h1>夫士大夫士大夫发</h1><p>会见韩国机构行家</p ><h2>地方鬼地方鬼地方三个广泛的</h2></body></html>";
htmlStringConvertToPDF(pdfFile,htmlContent2);
// parseHtml2PdfByFilePath(pdfFile,htmlFile);
} catch (Exception e) {
e.printStackTrace();
}
}
}
@@ -329,9 +329,10 @@ public class VideoServiceImpl implements VideoService {
} catch (IOException e) {
throw new RuntimeException(e);
}
String htmlContent = "<html><body style=\"font-size:12.0pt; font-family:宋体\">" +reservedConferenceVO.getHtmlContent()+"</body></html>";
String htmlContent = "<html><body style=\"font-size:12.0pt; font-family:SimSun;\">" +reservedConferenceVO.getHtmlContent()+"</body></html>";
// html转pdf并上传到服务器
boolean convertFlag = PdfUtils.htmlStringConvertToPDF(RuoYiConfig.getHtml2PDFPath() + currentFileName, htmlContent);
PdfUtils pdfUtils = new PdfUtils();
boolean convertFlag = pdfUtils.htmlStringConvertToPDF(RuoYiConfig.getHtml2PDFPath() + currentFileName, htmlContent);
// 绑定案件
if(convertFlag){