linux 下适配 转换pdf
continuous-integration/drone/push Build is passing Details

IRC_NewDev
hang 2023-11-30 13:33:51 +08:00
parent de1d971e44
commit 0cbb375a49
2 changed files with 57 additions and 8 deletions

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
@ -10,5 +11,29 @@ namespace IRaCIS.Core.Application.Helper
{
static public void ConvertWordToPdf(string inputWordFilePath, string outputPdfDir)
{
// 设置 libreoffice 命令行参数
string arguments = $"--headless --invisible --convert-to pdf \"{inputWordFilePath}\" --outdir \"{outputPdfDir}\"";
// 启动 libreoffice 进程
using (Process process = new Process())
{
process.StartInfo.FileName = "libreoffice";
process.StartInfo.Arguments = arguments;
process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
process.StartInfo.UseShellExecute = false;
process.StartInfo.CreateNoWindow = true;
process.Start();
// 等待进程结束
process.WaitForExit();
}
}
}
}

View File

@ -24,6 +24,8 @@ using Spire.Doc;
using Microsoft.AspNetCore.Http;
using System;
using System.Runtime.InteropServices;
using SharpCompress.Common;
using SkiaSharp;
namespace IRaCIS.Core.Application.Service
{
@ -59,7 +61,7 @@ namespace IRaCIS.Core.Application.Service
IRepository<SubjectVisit> subjectVisitRepository,
IRepository<TrialEmailBlackUser> trialEmailBlackUserRepository,
IRepository<EmailNoticeConfig> emailNoticeConfigRepository
, IEmailSendService emailSendService
, IEmailSendService emailSendService
)
{
_trialEmailNoticeConfigRepository = trialEmailNoticeConfigRepository;
@ -635,7 +637,7 @@ namespace IRaCIS.Core.Application.Service
FileStream = File.OpenRead(phyPath),
});
await SendEmailHelper.SendEmailAsync(sendEmailConfig);
return string.Empty;
@ -677,9 +679,17 @@ namespace IRaCIS.Core.Application.Service
}
else
{
var wordStoreServerPath = Path.Combine(Path.GetDirectoryName(serverFilePath), Path.GetFileNameWithoutExtension(serverFilePath)+".docx");
using (FileStream fileStream = new FileStream(wordStoreServerPath, FileMode.Create, FileAccess.Write))
{
wordMemoryStream.WriteTo(fileStream);
}
FileConvertHelper.ConvertWordToPdf(wordStoreServerPath, Path.GetDirectoryName(serverFilePath));
File.Delete(wordStoreServerPath);
}
}
@ -697,25 +707,39 @@ namespace IRaCIS.Core.Application.Service
{
MemoryStream memoryStream = new MemoryStream();
MemoryStream wordMemoryStream = new MemoryStream();
MemoryStream pdfMemoryStream = new MemoryStream();
MiniSoftware.MiniWord.SaveAsByTemplate(memoryStream, path, value);
MiniSoftware.MiniWord.SaveAsByTemplate(wordMemoryStream, path, value);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
Document document = new Document();
document.LoadFromStream(memoryStream, FileFormat.Docx);
document.LoadFromStream(wordMemoryStream, FileFormat.Docx);
document.SaveToStream(pdfMemoryStream, FileFormat.PDF);
}
else
{
var wordStoreServerPath = Path.Combine(Path.GetDirectoryName(serverFilePath), Path.GetFileNameWithoutExtension(serverFilePath) + ".docx");
using (FileStream fileStream = new FileStream(wordStoreServerPath, FileMode.Create, FileAccess.Write))
{
wordMemoryStream.WriteTo(fileStream);
}
FileConvertHelper.ConvertWordToPdf(wordStoreServerPath, Path.GetDirectoryName(serverFilePath));
File.Delete(wordStoreServerPath);
using (FileStream fileStream = new FileStream(serverFilePath, FileMode.Open, FileAccess.Read))
{
fileStream.CopyTo(pdfMemoryStream);
}
}
pdfMemoryStream.Seek(0, SeekOrigin.Begin);
pdfMemoryStream.Seek(0, SeekOrigin.Begin);
sendEmailConfig.EmailAttachMentConfigList.Add(new EmailAttachMentConfig()
{
FileName = $"{taskInfo.SubjectCode}_{Path.GetFileNameWithoutExtension(_userInfo.IsEn_Us ? trialEmailConfig.AttachName : trialEmailConfig.AttachNameCN)}.pdf",