原文链接:http://www.cnblogs.com/ayzhanglei/p/9111836.html原文链接:http://www.cnblogs.com/ayzhanglei/p/9111836.html1.安装libreoffice,我的服务器是centos,直接使用: yum install libreoffice 2.因为CentOS 里面没有中文字体,文件中有中文会出现乱码,解...
1.安装libreoffice,我的服务器是centos,直接使用:
yum install libreoffice
2.因为CentOS 里面没有中文字体,文件中有中文会出现乱码,解决方案
先把 c:\Windows\Fonts文件夹复制一份到其它盘,然后打包成Fonts.zip,通过rz Fonts.zip 将压缩包传到服务器上面。
cd /usr/share/fonts
rz
unzip Fonts.zip
mv Fonts win
cd win
chmod -Rf 755 *
mkfontscale
mkfontdir
fc-cache –fv
3.使用命令转换成pdf文件
libreoffice --invisible --convert-to pdf DanaZhang.docx
4.使用dotnet core 转化
using System;
using System.Diagnostics;
namespace DanaZhang
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Hello DanaZhang!");
var psi = new ProcessStartInfo("libreoffice", "--invisible --convert-to pdf DanaZhang.docx") { RedirectStandardOutput = true };
//启动
var proc = Process.Start(psi);
if (proc == null)
{
Console.WriteLine("不能执行.");
}
else
{
Console.WriteLine("-------------开始执行--------------");
//开始读取
using (var sr = proc.StandardOutput)
{
while (!sr.EndOfStream)
{
Console.WriteLine(sr.ReadLine());
}
if (!proc.HasExited)
{
proc.Kill();
}
}
Console.WriteLine("---------------执行完成------------------");
Console.WriteLine($"退出代码 : {proc.ExitCode}");
}
}
}
}
转载于:https://www.cnblogs.com/ayzhanglei/p/9111836.html
沃梦达教程
本文标题为:dotnet core 在CentOS下 使用libreoffice 把Office 转换成pdf
猜你喜欢
- 如何使用C# 捕获进程输出 2023-03-10
- .NET CORE DI 依赖注入 2023-09-27
- WPF使用DrawingContext实现绘制刻度条 2023-07-04
- 在C# 8中如何使用默认接口方法详解 2023-03-29
- c# 模拟线性回归的示例 2023-03-14
- Unity Shader实现模糊效果 2023-04-27
- C# 使用Aspose.Cells 导出Excel的步骤及问题记录 2023-05-16
- user32.dll 函数说明小结 2022-12-26
- Oracle中for循环的使用方法 2023-07-04
- Unity3D实现渐变颜色效果 2023-01-16