原文链接: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#中的Linq to JSON操作详解 2023-06-08
- c# – USING块在网站与Windows窗体中的行为不同 2023-09-20
- Unity 如何获取鼠标停留位置下的物体 2023-04-10
- C# 解析XML和反序列化的示例 2023-04-14
- 实例详解C#实现http不同方法的请求 2022-12-26
- C#通过标签软件Bartender的ZPL命令打印条码 2023-05-16
- C#中 Json 序列化去掉null值的方法 2022-11-18
- C#获取指定目录下某种格式文件集并备份到指定文件夹 2023-05-30
- Unity shader实现高斯模糊效果 2023-01-16
- C#调用摄像头实现拍照功能的示例代码 2023-03-09