语音转录

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.api.IConverter;
import com.documents4j.job.LocalConverter; import com.documents4j.job.LocalConverter;
import com.itextpdf.text.Document; import com.itextpdf.text.Document;
import com.itextpdf.text.Font;
import com.itextpdf.text.PageSize; import com.itextpdf.text.PageSize;
import com.itextpdf.text.pdf.BaseFont;
import com.itextpdf.text.pdf.PdfWriter; import com.itextpdf.text.pdf.PdfWriter;
import com.itextpdf.tool.xml.XMLWorkerFontProvider;
import com.itextpdf.tool.xml.XMLWorkerHelper; 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.io.*;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import static cn.hutool.core.util.ClassLoaderUtil.getClassLoader;
/** /**
* @author wangqiong * @author wangqiong
* @description pdf转换工具类 * @description pdf转换工具类
* @date 2023-11-28 15:20 * @date 2023-11-28 15:20
*/ */
@Slf4j
public class PdfUtils { public class PdfUtils {
/** /**
* 将html字符串转为pdf * 将html字符串转为pdf
* @param pdfFilePath 保存的路径 * @param pdfFilePath 保存的路径
* @param htmlcontent:必须是完整的html格式,比如<html><body>123</body></html> * @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(); Document document = new Document();
PdfWriter writer = null; PdfWriter writer = null;
try { try {
if(!new File(pdfFilePath).exists()){ // if(!new File(pdfFilePath).exists()){
new File(pdfFilePath).createNewFile(); // new File(pdfFilePath).createNewFile();
} // }
writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFilePath)); writer = PdfWriter.getInstance(document, new FileOutputStream(pdfFilePath));
// 设置底部距离60,解决重叠问题 // 设置底部距离60,解决重叠问题
document.setPageSize(PageSize.A4); document.setPageSize(PageSize.A4);
document.setMargins(50, 45, 50, 60); document.setMargins(50, 45, 50, 60);
document.setMarginMirroring(false); document.setMarginMirroring(false);
document.open(); 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) { } catch (Exception e) {
log.error("htmlStringConvertToPDF error", e.getMessage());
return false; return false;
} finally { } finally {
if (null != document) { if (null != document) {
@@ -131,18 +147,4 @@ public class PdfUtils {
return true; 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) { } catch (IOException e) {
throw new RuntimeException(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并上传到服务器 // html转pdf并上传到服务器
boolean convertFlag = PdfUtils.htmlStringConvertToPDF(RuoYiConfig.getHtml2PDFPath() + currentFileName, htmlContent); PdfUtils pdfUtils = new PdfUtils();
boolean convertFlag = pdfUtils.htmlStringConvertToPDF(RuoYiConfig.getHtml2PDFPath() + currentFileName, htmlContent);
// 绑定案件 // 绑定案件
if(convertFlag){ if(convertFlag){