コード例 #1
0
        public HttpResponseMessage GetReportYN(dynamic html)
        {
            string result = "";

            try
            {
                AsposeWordsHelper wd       = new AsposeWordsHelper();
                string            filename = @html.path.ToString() + @"\" + html.filename.ToString() + ".doc";
                html.projectpath = html.projectpath.ToString().Replace(@"\\", @"/");
                if (html.allhtml.ToString().Contains("img"))
                {
                    html.allhtml = html.allhtml.ToString().Replace(@"static/img/", html.projectpath.ToString() + @"/");
                }
                //判断文件夹是否存在 如果不存在就创建
                if (!Directory.Exists(html.path.ToString()))
                {
                    Directory.CreateDirectory(html.path.ToString());
                }
                wd.htmlword("<html><head></head><body>" + html.allhtml + "</body></html>", filename);
                result = rule.JsonStr("ok", "", filename);;
            }
            catch (Exception e)
            {
                result = rule.JsonStr("error", "", e.Message);
            }

            return(new HttpResponseMessage {
                Content = new StringContent(result, System.Text.Encoding.UTF8, "application/json")
            });
        }
コード例 #2
0
        public ActionResult Post([FromBody] FileConvert fileConvert)
        {
            string msg = "error converting document";

            try
            {
                AsposeWordsHelper helper  = new AsposeWordsHelper();
                byte[]            outFile = null;
                bool hasSignatures        = false;
                try
                {
                    hasSignatures = helper.CheckWordFileForDigitalSignatures(fileConvert.fileLocation);
                }
                catch (Exception ex) { }

                if (!hasSignatures)
                {
                    switch (fileConvert.convertTo.ToLower())
                    {
                    case "rtf":
                        outFile = helper.ConvertToRTF(fileConvert.fileLocation);
                        break;

                    case "pdf":
                        outFile = helper.ConvertToPDF(fileConvert.fileLocation);
                        break;

                    case "docx":
                        outFile = helper.ConvertToDOCX(fileConvert.fileLocation);
                        break;

                    default:
                        msg = "this file format is not yet supported";
                        throw new Exception("This file format is not yet supported.");
                    }
                }
                else
                {
                    throw new Exception("This file has signatures and cannot be converted.");
                }

                string fileStr = Convert.ToBase64String(outFile);

                return(Json(new { file = fileStr }));
            }
            catch (Exception ex)
            {
                return(BadRequest(msg));
            }
        }