Exemplo n.º 1
0
        /// <summary>
        /// 加载doc模板
        /// </summary>
        /// <param name="templateName">模板名称 docName  例如:路径为:/Templates/docName.docx  则为:docName</param>
        public void Load(string templateName)
        {
            string mapPath = HttpContext.Current.Server.MapPath(VirtualPathUtility.GetDirectory("~"));
            string path    = string.Format(@"{0}Templates\{1}.docx", mapPath, templateName);

            this.document      = DocX.Load(path);
            this.configManager = new FlexPaperConfig(mapPath);
        }
Exemplo n.º 2
0
        public IHttpActionResult View()
        {
            string          dir           = HttpContext.Current.Server.MapPath(VirtualPathUtility.GetDirectory("~"));
            FlexPaperConfig configManager = new FlexPaperConfig(dir);
            string          doc           = HttpContext.Current.Request["doc"];
            string          page          = HttpContext.Current.Request["page"];

            string swfFilePath = configManager.getConfig("path.swf") + doc + page + ".swf";
            string pdfFilePath = configManager.getConfig("path.pdf") + doc;

            if (!Util.validPdfParams(pdfFilePath, doc, page))
            {
                HttpContext.Current.Response.Write("[Incorrect file specified]");
            }
            else
            {
                String output = new pdf2swf(dir).convert(doc, page);
                if (output.Equals("[Converted]"))
                {
                    if (configManager.getConfig("allowcache") == "true")
                    {
                        Util.setCacheHeaders(HttpContext.Current);
                    }

                    HttpContext.Current.Response.AddHeader("Content-type", "application/x-shockwave-flash");
                    HttpContext.Current.Response.AddHeader("Accept-Ranges", "bytes");
                    HttpContext.Current.Response.AddHeader("Content-Length", new System.IO.FileInfo(swfFilePath).Length.ToString());

                    HttpContext.Current.Response.WriteFile(swfFilePath);
                }
                else
                {
                    HttpContext.Current.Response.Write(output);
                }
            }
            HttpContext.Current.Response.End();
            if (File.Exists(pdfFilePath))
            {
                File.Delete(pdfFilePath);
            }
            if (File.Exists(swfFilePath))
            {
                File.Delete(swfFilePath);
            }
            return(Ok());
        }
Exemplo n.º 3
0
        //加載模板
        public void LoadModelDoc(string templateName)
        {
            string mapPath = HttpContext.Current.Server.MapPath(VirtualPathUtility.GetDirectory("~"));
            string path    = string.Format(@"{0}Templates\{1}.docx", mapPath, templateName);

            var nextPageBrakerTemplate = string.Format(@"{0}Templates\{1}.docx", mapPath, "_NextPageBreaker");
            var nextPageBreakerDocX    = DocX.Load(nextPageBrakerTemplate);

            if (null == nextPageBreakerDocX ||
                null == nextPageBreakerDocX.Paragraphs ||
                nextPageBreakerDocX.Paragraphs.Count < 2)
            {
                throw new Exception("Failed to Load NextPageBreaker");
            }

            this.nextPageBreaker = nextPageBreakerDocX.Paragraphs[0];

            partDocumentModel  = DocX.Load(path);
            this.configManager = new FlexPaperConfig(mapPath);
        }