• dotnet core 在CentOS下 使用libreoffice 把Office 转换成pdf


    1.安装libreoffice,我的服务器是centos,直接使用:

             

    yum install libreoffice  
    

      

     2.因为CentOS 里面没有中文字体,文件中有中文会出现乱码,解决方案

    先把 c:WindowsFonts文件夹复制一份到其它盘,然后打包成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}");
                }
    
            }
        }
    }
    

      

      

  • 相关阅读:
    linux 常用命令
    books list
    开发文化,沟通、会议、总结
    编程资源
    敏捷开发流程
    服务器安全部署指南
    服务器应用部署规范
    单元测试
    弱弱的页码问题
    实验A javaScript XML数据操作按姓名查询
  • 原文地址:https://www.cnblogs.com/ayzhanglei/p/9111836.html
Copyright © 2020-2023  润新知