コード例 #1
0
        public ActionResult Download(string id, string format)
        {
            string LicenseFilePath = ConfigurationManager.AppSettings["LicenseFilePath"];

            if (System.IO.File.Exists(LicenseFilePath))
            {
                GroupDocs.Editor.License license = new GroupDocs.Editor.License(); // Instantiate GroupDocs.Editor license
                license.SetLicense(LicenseFilePath);                               // Apply GroupDocs.Editor license using license path
            }

            Document myDocument = Utils.GetDocument(id);

            WordFormats      saveFormat         = Utils.GetSaveFormat(format);
            string           password           = string.Empty;
            WordsSaveOptions saveOptions        = new WordsSaveOptions(saveFormat, password);
            string           resourcesDirectory = Server.MapPath("/App_Data/Samples");
            string           resultFileName     = myDocument.Name + "." + format;
            string           resultFilePath     = Server.MapPath("/App_Data/Downloads") + "\\" + resultFileName;

            using (OutputHtmlDocument htmlDoc = OutputHtmlDocument.FromMarkup(myDocument.HTML, resourcesDirectory))
            {
                using (System.IO.FileStream outputFile = System.IO.File.Create(resultFilePath))
                {
                    EditorHandler.ToDocument(htmlDoc, outputFile, saveOptions);
                    return(File(resultFilePath, "application/vnd.openxmlformats-officedocument.wordprocessingml.document", resultFileName));
                }
            }
        }
コード例 #2
0
        public string GenerateWordsDoc(string itemFolderPath)
        {
            string ext = itemFolderPath.Split('_').LastOrDefault();

            string targetFilePath   = System.IO.Path.Combine(itemFolderPath, string.Format("output.{0}", ext));
            string editedFolderPath = System.IO.Path.Combine(itemFolderPath, Constants.EditedFolderName);

            Repository.CreateFolderIfNotExists(editedFolderPath);
            string editedResourceFolderPath = System.IO.Path.Combine(itemFolderPath, Constants.EditedFolderName, Constants.HtmlResourceFolderName);
            string newHtmlFilePath          = System.IO.Path.Combine(itemFolderPath, Constants.EditedFolderName, Constants.HtmlFilename);

            if (!this._isNewArticle)
            {
                string originalResourceFolderPath = System.IO.Path.Combine(itemFolderPath, Constants.OriginalFolderName, Constants.HtmlResourceFolderName);
                if (System.IO.Directory.Exists(originalResourceFolderPath))
                {
                    Repository.Copy(originalResourceFolderPath, editedResourceFolderPath);
                }
            }
            else //if (this._isNewArticle)
            {
                Repository.CreateFolderIfNotExists(editedResourceFolderPath);
            }

            using (OutputHtmlDocument editedHtmlDoc = OutputHtmlDocument.FromMarkup(this._editedDocumentHtmlContent, editedResourceFolderPath))
            {
                // the commented source code below is not necessary for this particular scenario, but shows a way to establish an association
                // between links and resources in more complex scenarios, when link doesn't contain resource name at all

                /*
                 * editedHtmlDoc.LinkToResourceMapper = delegate(string linkToResource, List<IHtmlResource> resources)
                 * {
                 *  foreach (IHtmlResource htmlResource in resources)
                 *  {
                 *      if (linkToResource.Contains(htmlResource.FilenameWithExtension))
                 *      {
                 *          return htmlResource;
                 *      }
                 *  }
                 *  return null;
                 * };
                 */
                System.IO.File.WriteAllText(newHtmlFilePath, editedHtmlDoc.HtmlMarkup);

                WordFormats      saveFormat  = GetSaveFormat(ext);
                WordsSaveOptions saveOptions = new WordsSaveOptions(saveFormat, this._closingPassword);
                saveOptions.Locale        = this._locale;
                saveOptions.LocaleBi      = this._localeRtl;
                saveOptions.LocaleFarEast = this._localeEa;

                using (System.IO.FileStream outputStream = System.IO.File.Create(targetFilePath))
                {
                    EditorHandler.ToDocument(editedHtmlDoc, outputStream, saveOptions);
                }
            }
            return(targetFilePath);
        }
コード例 #3
0
        public String GetPlaceName()
        {
            if (Rand.Next(3) != 0)
            {
                return(ConstructWord(5, 8));
            }
            if (WordFormats.Count == 0)
            {
                for (int n = 0; n < 1; n++)
                {
                    WordFormats.Add(CommonWordFormats[Rand.Next(CommonWordFormats.Count)]);
                }
            }
            if (wordsForLand.Count == 0)
            {
                string s = ConstructWord(2 * wordLengthBias, 4 * wordLengthBias);
                wordsForLand.Add(s);
            }

            if (placeFormat == null)
            {
                placeFormat = placeFormatOptions[Rand.Next(placeFormatOptions.Count())];
            }

            string format = this.WordFormats[Rand.Next(WordFormats.Count)];

            int nWords = 1;

            if (Rand.Next(3) == 0)
            {
                nWords++;
            }

            if (Rand.Next(3) == 0)
            {
                nWords++;
            }
            if (Rand.Next(3) != 0)
            {
                format = "{0}";
                nWords = 1;
            }

            int index = 0;

            if (nWords == 1)
            {
                index  = format.IndexOf("{0}") + 3;
                format = format.Substring(0, index);
            }
            if (nWords == 2)
            {
                index  = format.IndexOf("{1}") + 3;
                format = format.Substring(0, index);
            }
            String[] strs = new String[nWords];
            for (int n = 0; n < nWords; n++)
            {
                if (nWords == 1)
                {
                    strs[n] = ConstructWord(5 * wordLengthBias, 8 * wordLengthBias);
                }
                else if (nWords == 2)
                {
                    strs[n] = ConstructWord(3 * wordLengthBias, 5 * wordLengthBias);
                }
                else if (nWords == 3)
                {
                    strs[n] = ConstructWord(3 * wordLengthBias, 4 * wordLengthBias);
                }
            }
            if (nWords == 1)
            {
                var s = Capitalize(String.Format(format, strs[0]));
                if (LanguageManager.instance.Get(StarNames.SafeName(s)) != null)
                {
                    return(GetPlaceName());
                }
                return(s);
            }
            else if (nWords == 2)
            {
                var s = Capitalize(String.Format(format, strs[0], strs[1]));
                if (LanguageManager.instance.Get(StarNames.SafeName(s)) != null)
                {
                    return(GetPlaceName());
                }
                return(s);
            }
            else
            {
                var s = Capitalize(String.Format(format, strs[0], strs[1], strs[2]));
                if (LanguageManager.instance.Get(StarNames.SafeName(s)) != null)
                {
                    return(GetPlaceName());
                }
                return(s);
            }
        }
コード例 #4
0
        public String GetPlaceName()
        {
            if (WordFormats.Count == 0)
            {
                for (int n = 0; n < 1; n++)
                {
                    WordFormats.Add(CommonWordFormats[Rand.Next(CommonWordFormats.Count)]);
                }
            }
            if (wordsForLand.Count == 0)
            {
                string s = ConstructWord(2 * wordLengthBias, 4 * wordLengthBias);
                wordsForLand.Add(s);
            }

            if (placeFormat == null)
            {
                placeFormat = placeFormatOptions[Rand.Next(placeFormatOptions.Count())];
            }

            string format = this.WordFormats[Rand.Next(WordFormats.Count)];

            int nWords = 1;

            if (Rand.Next(3) == 0)
            {
                nWords++;
            }

            if (Rand.Next(3) == 0)
            {
                nWords++;
            }

            int index = 0;

            if (nWords == 1)
            {
                index  = format.IndexOf("{0}") + 3;
                format = format.Substring(0, index);
            }
            if (nWords == 2)
            {
                index  = format.IndexOf("{1}") + 3;
                format = format.Substring(0, index);
            }
            String[] strs = new String[nWords];
            for (int n = 0; n < nWords; n++)
            {
                if (nWords == 1)
                {
                    strs[n] = ConstructWord(5 * wordLengthBias, 8 * wordLengthBias);
                }
                else if (nWords == 2)
                {
                    strs[n] = ConstructWord(3 * wordLengthBias, 5 * wordLengthBias);
                }
                else if (nWords == 3)
                {
                    strs[n] = ConstructWord(2 * wordLengthBias, 4 * wordLengthBias);
                }
            }
            if (nWords == 1)
            {
                return(Capitalize(String.Format(format, strs[0])));
            }
            else if (nWords == 2)
            {
                return(Capitalize(String.Format(format, strs[0], strs[1])));
            }
            else
            {
                return(Capitalize(String.Format(format, strs[0], strs[1], strs[2])));
            }

            if (Rand.Next(2) == 0)
            {
                return
                    (Capitalize(String.Format(placeFormat, wordsForLand[Rand.Next(wordsForLand.Count)],
                                              ConstructWord(3 * wordLengthBias, 7 * wordLengthBias))));
            }
            else
            {
                if (Rand.Next(4) == 0)
                {
                    return(ConstructWord(6 * wordLengthBias, 8 * wordLengthBias));
                }
                else
                {
                    return(Capitalize(ConstructWord(3 * wordLengthBias, 5 * wordLengthBias) + " " + ConstructWord(3 * wordLengthBias, 4 * wordLengthBias)));
                }
            }
        }
コード例 #5
0
ファイル: WordDocument.cs プロジェクト: TomRom27/LectioDivina
        public void SaveAsDifferentFormat(string newName, WordFormats format)
        {
            EnsureDocument();

            object fileName = newName;
            object formatObj;

            switch (format)
            {
                case WordFormats.WordDoc:
                    {
                        formatObj = MSWord.WdSaveFormat.wdFormatDocument97;
                        break;
                    }
                case WordFormats.Pdf:
                    {
                        formatObj = MSWord.WdSaveFormat.wdFormatPDF;
                        break;
                    }
                default:
                    {
                        formatObj = MSWord.WdSaveFormat.wdFormatDocumentDefault;
                        break;
                    }
            }

            doc.SaveAs(ref fileName, ref formatObj, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
                        ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
        }