linux 下适配 转换pdf
parent
dee286cc90
commit
48b778c95a
|
@ -1,5 +1,6 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,8 @@ using Spire.Doc;
|
||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using System;
|
using System;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
using SharpCompress.Common;
|
||||||
|
using SkiaSharp;
|
||||||
|
|
||||||
namespace IRaCIS.Core.Application.Service
|
namespace IRaCIS.Core.Application.Service
|
||||||
{
|
{
|
||||||
|
@ -59,6 +61,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
IRepository<SubjectVisit> subjectVisitRepository,
|
IRepository<SubjectVisit> subjectVisitRepository,
|
||||||
IRepository<TrialEmailBlackUser> trialEmailBlackUserRepository,
|
IRepository<TrialEmailBlackUser> trialEmailBlackUserRepository,
|
||||||
IRepository<EmailNoticeConfig> emailNoticeConfigRepository
|
IRepository<EmailNoticeConfig> emailNoticeConfigRepository
|
||||||
|
, IEmailSendService emailSendService
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
_trialEmailNoticeConfigRepository = trialEmailNoticeConfigRepository;
|
_trialEmailNoticeConfigRepository = trialEmailNoticeConfigRepository;
|
||||||
|
@ -812,7 +815,7 @@ namespace IRaCIS.Core.Application.Service
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
await SendEmailHelper.SendEmailAsync(sendEmailConfig);
|
await SendEmailHelper.SendEmailAsync(sendEmailConfig);
|
||||||
|
|
||||||
return string.Empty;
|
return string.Empty;
|
||||||
}
|
}
|
||||||
|
@ -851,9 +854,17 @@ namespace IRaCIS.Core.Application.Service
|
||||||
}
|
}
|
||||||
else
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -871,28 +882,42 @@ namespace IRaCIS.Core.Application.Service
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
MemoryStream memoryStream = new MemoryStream();
|
MemoryStream wordMemoryStream = new MemoryStream();
|
||||||
MemoryStream pdfMemoryStream = new MemoryStream();
|
MemoryStream pdfMemoryStream = new MemoryStream();
|
||||||
|
|
||||||
|
|
||||||
MiniSoftware.MiniWord.SaveAsByTemplate(memoryStream, path, value);
|
MiniSoftware.MiniWord.SaveAsByTemplate(wordMemoryStream, path, value);
|
||||||
|
|
||||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
|
||||||
{
|
{
|
||||||
Document document = new Document();
|
Document document = new Document();
|
||||||
document.LoadFromStream(memoryStream, FileFormat.Docx);
|
document.LoadFromStream(wordMemoryStream, FileFormat.Docx);
|
||||||
document.SaveToStream(pdfMemoryStream, FileFormat.PDF);
|
document.SaveToStream(pdfMemoryStream, FileFormat.PDF);
|
||||||
|
|
||||||
}
|
}
|
||||||
else
|
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);
|
|
||||||
|
|
||||||
sendEmailConfig.EmailAttachMentConfigList.Add(new EmailAttachMentConfig()
|
pdfMemoryStream.Seek(0, SeekOrigin.Begin);
|
||||||
{
|
sendEmailConfig.EmailAttachMentConfigList.Add(new EmailAttachMentConfig()
|
||||||
FileName = $"{taskInfo.SubjectCode}_{Path.GetFileNameWithoutExtension(_userInfo.IsEn_Us ? emailConfig.AttachName : emailConfig.AttachNameCN)}.pdf",
|
{
|
||||||
|
FileName = $"{taskInfo.SubjectCode}_{Path.GetFileNameWithoutExtension(_userInfo.IsEn_Us ? trialEmailConfig.AttachName : trialEmailConfig.AttachNameCN)}.pdf",
|
||||||
|
|
||||||
FileStream = pdfMemoryStream
|
FileStream = pdfMemoryStream
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue