当前位置: 首页 > news >正文

红古微信网站建设构建电子商务网站的步骤

红古微信网站建设,构建电子商务网站的步骤,国际网站建设与维护,做怎样的网站能赚钱在程序开发中经常需要将Office文件转换成PDF#xff0c;著名的Aspose的三大组件可以很容易完成这个功能#xff0c;但是Aspose的每个组件都单独收费#xff0c;而且每个都卖的不便宜。在老大的提示下#xff0c;换了一种思路来解决这个问题。环境dotNetCore:2.1CentOS:7.5D… 在程序开发中经常需要将Office文件转换成PDF著名的Aspose的三大组件可以很容易完成这个功能但是Aspose的每个组件都单独收费而且每个都卖的不便宜。在老大的提示下换了一种思路来解决这个问题。环境dotNetCore:2.1CentOS:7.5Docker:18.06.1-ce步骤1、Docker中安装libreoffice和dotNetCore2、编写转换程序3、程序以服务的方式部署在Docker中。配置Docker环境因为需要部署dotNetCore的程序开始的想法是依赖microsoft/dotnet:2.1-aspnetcore-runtime镜像创建容器然后在容器中安装libreoffice后来发现容器中没法执行yum命令可能是没找到方法。最后换了一种思路依赖centos镜像创建容器在容器中安装dotNetCore2.1和libreoffice。安装libreofiicieyum install libreoffice 安装dotnetCore2.1sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpmsudo yum updatesudo yum install aspnetcore-runtime-2.1sudo yum updatesudo yum install aspnetcore-runtime-2.1转换程序编写在C#中使用libreoffice转换office为pdf网上有很多的代码示例在这里还需要引入消息队列整个程序是一个消息队列的消费者。简单说就是用户上传了一个office文件上传成功后会发一个消息该程序中接收到消息就进行转换。消息监听    class Program    {        static IPowerPointConverter converter  new PowerPointConverter();        static void Main(string[] args)        {            var mqManager  new MQManager(new MqConfig            {                AutomaticRecoveryEnabled  true,                HeartBeat  60,                NetworkRecoveryInterval  new TimeSpan(60),                Host  ConfigurationManager.AppSettings[mqhostname],                 UserName  ConfigurationManager.AppSettings[mqusername],                Password  ConfigurationManager.AppSettings[mqpassword],                Port  ConfigurationManager.AppSettings[mqport]            });            if (mqManager ! null  mqManager.Connected)            {                Console.WriteLine(RabbitMQ连接初始化成功。);                Console.WriteLine(RabbitMQ消息接收中...);                mqManager.SubscribePowerPointConvertMessage(message                 {                    if (message ! null)                    {                        converter.OnWork(message);                        Console.WriteLine(message.FileInfo);                    }                });            }            else            {                Console.WriteLine(RabbitMQ连接初始化失败,请检查连接。);                Console.ReadLine();            }        }    }Program    {        static IPowerPointConverter converter  new PowerPointConverter();        static void Main(string[] args)        {            var mqManager  new MQManager(new MqConfig            {                AutomaticRecoveryEnabled  true,                HeartBeat  60,                NetworkRecoveryInterval  new TimeSpan(60),                Host  ConfigurationManager.AppSettings[mqhostname],                 UserName  ConfigurationManager.AppSettings[mqusername],                Password  ConfigurationManager.AppSettings[mqpassword],                Port  ConfigurationManager.AppSettings[mqport]            });            if (mqManager ! null  mqManager.Connected)            {                Console.WriteLine(RabbitMQ连接初始化成功。);                Console.WriteLine(RabbitMQ消息接收中...);                mqManager.SubscribePowerPointConvertMessage(message                 {                    if (message ! null)                    {                        converter.OnWork(message);                        Console.WriteLine(message.FileInfo);                    }                });            }            else            {                Console.WriteLine(RabbitMQ连接初始化失败,请检查连接。);                Console.ReadLine();            }        }    }文件转换        public bool OnWork(MQ.Messages Message)        {            PowerPointConvertMessage message  (PowerPointConvertMessage)Message;            string sourcePath  string.Empty;            string destPath  string.Empty;            try            {                if(message  null)                    return false;                Stream sourceStream  fileOperation.GetFile(message.FileInfo.FileId);                string filename  message.FileInfo.FileId;                string extension  System.IO.Path.GetExtension(message.FileInfo.FileName);                sourcePath  System.IO.Path.Combine(Directory.GetCurrentDirectory(), filename  extension);                destPath  System.IO.Path.Combine(Directory.GetCurrentDirectory(), string.Format({0}.pdf, filename));                if (!SaveToFile(sourceStream, sourcePath))                    return false;                var psi  new ProcessStartInfo(libreoffice, string.Format(--invisible --convert-to pdf  {0}, filename  extension)) { RedirectStandardOutput  true };                // 启动                var proc  Process.Start(psi);                if (proc  null)                {                    Console.WriteLine(不能执行.);                    return false;                }                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});                }            }            catch (Exception ex)            {                Console.WriteLine(ex.Message);                return false;            }            finally            {                if (File.Exists(destPath))                {                    var destFileInfo  UploadFile(destPath, string.Format({0}.pdf, Path.GetFileNameWithoutExtension(message.FileInfo.FileName)));                }                if (File.Exists(destPath))                {                    System.IO.File.Delete(destPath);                }            }            return true;        }            PowerPointConvertMessage message  (PowerPointConvertMessage)Message;            string sourcePath  string.Empty;            string destPath  string.Empty;            try            {                if(message  null)                    return false;                Stream sourceStream  fileOperation.GetFile(message.FileInfo.FileId);                string filename  message.FileInfo.FileId;                string extension  System.IO.Path.GetExtension(message.FileInfo.FileName);                sourcePath  System.IO.Path.Combine(Directory.GetCurrentDirectory(), filename  extension);                destPath  System.IO.Path.Combine(Directory.GetCurrentDirectory(), string.Format({0}.pdf, filename));                if (!SaveToFile(sourceStream, sourcePath))                    return false;                var psi  new ProcessStartInfo(libreoffice, string.Format(--invisible --convert-to pdf  {0}, filename  extension)) { RedirectStandardOutput  true };                // 启动                var proc  Process.Start(psi);                if (proc  null)                {                    Console.WriteLine(不能执行.);                    return false;                }                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});                }            }            catch (Exception ex)            {                Console.WriteLine(ex.Message);                return false;            }            finally            {                if (File.Exists(destPath))                {                    var destFileInfo  UploadFile(destPath, string.Format({0}.pdf, Path.GetFileNameWithoutExtension(message.FileInfo.FileName)));                }                if (File.Exists(destPath))                {                    System.IO.File.Delete(destPath);                }            }            return true;        }上面只是一些代码片段完整示例会上传到Github上文章末尾会给出地址。部署代码到Docker此程序是dotNetCore编写的控制台程序希望以服务的方式在后台运行下面介绍怎样将控制台程序以服务的方式运行1、将发布后的代码放在容器的/root/officetopdf/publish目录中2、在 /lib/systemd/system目录中创建文件officetopdf.service3、文件内容如下[Unit]Descriptionoffice to pdf service[Service]ExecStart/usr/bin/dotnet /root/officetopdf/publish/Office2PDF.dll[Install]WantedBydefault.targetDescriptionoffice to pdf service[Service]ExecStart/usr/bin/dotnet /root/officetopdf/publish/Office2PDF.dll[Install]WantedBydefault.target4、使用下面命令创建和启动服务systemctrl daemon-reloadsystemctrl start officetopdfsystemctrl start officetopdf示例https://github.com/oec2003/StudySamples/tree/master/Office2PDF
http://www.zqtcl.cn/news/22211/

相关文章:

  • 苏州做网站公司乛 苏州聚尚网络html动态页面代码
  • 珠海网站建设优化推广百度站长平台提交网站
  • 聊城建网站网站流量怎么查看
  • 免费做手机网站建设湖州童装网站
  • 广州seo网站设计高校财务网站建设
  • wordpress淘宝客建站教程wordpress移动端音频播放
  • 毕业设计做旅游网站wordpress返现
  • 湖北城市建设职业技术学院教务网站做微信首图的网站
  • 庆阳市西峰区做网站2345浏览器怎么卸载最干净
  • 做网站能赚能去什么公司wordpress 汽车
  • 企业网站建设用什么门户网站有什么特点
  • 网站维护是谁做的购物商城网站开发实验报告
  • 苏州做网站费用明细个人网站命名技巧
  • 网站框架一般用什么做学网站开发怎么样
  • 做网站的支付宝安做网站公司
  • 天津营销型网站建设公众号怎么建立
  • 万网 速成网站美食网站开发背景
  • 杭州建设工程交易中心网站套模板的网站
  • 学做土建资料员的网站晋城做推广的网站排行
  • 北京建设银行网站理财产品上海小程序开发定制公司
  • 自助开通网站dede被挂网站网站木马
  • 网站 框架51网站哪里去了
  • asp做的网站做网站现在什么最赚钱
  • 网站卡密代理怎么做discuz论坛使用方法
  • 网站建设平台一般多少钱社交媒体市场营销
  • 泰安集团网站建设广州网站定制多少钱
  • 互联网 网站设计网络营销推广策划书
  • 高端品牌网站建设公司上海建筑公司黄页
  • 网站seo推广的方法铜川做网站电话
  • 男女做羞羞完整版网站杭州seo外包