Exemple #1
0
        public IConverter GetConverter(ContentType contentType)
        {
            IConverter converter = null;

            switch (contentType)
            {
            case ContentType.DOC:
            case ContentType.DOCX:
                converter = new WordConverter();
                break;

            case ContentType.XLS:
            case ContentType.XLSX:
                converter = new ExcelConverter();
                break;

            case ContentType.PPT:
            case ContentType.PPTX:
                converter = new PowerpointConverter();
                break;

            default:
                break;
            }
            return(converter);
        }
Exemple #2
0
        private void TestWordFile(
            List <PollerTestResult> retValue,
            String fileName,
            String type,
            Byte[] fileContent)
        {
            try
            {
                var tempFile = Path.Combine(Path.GetTempPath(), fileName);
                if (File.Exists(tempFile))
                {
                    File.Delete(tempFile);
                }
                File.WriteAllBytes(tempFile, fileContent);

                var conversionError = WordConverter.ConvertToPdf(tempFile, tempFile + ".pdf");
                if (!String.IsNullOrEmpty(conversionError))
                {
                    retValue.Add(new PollerTestResult(false, type + "Conversion with word converter failed: " + conversionError));
                }
                else
                {
                    retValue.Add(new PollerTestResult(true, type + "Conversion with word ok."));
                }
            }
            catch (Exception ex)
            {
                retValue.Add(new PollerTestResult(false, type + "Conversion with word converter failed: " + ex.Message));
            }
        }
        public void RemoveConverter(WordConverter cvt)
        {
            // 移除已知的轉換器。

            if (cvt is ContextTagConverter)
            {
                m_ContextTagConverter = null;
                return;
            }
            if (cvt is ChineseWordConverter)
            {
                m_ChineseConverter = null;
                return;
            }
            if (cvt is EnglishWordConverter)
            {
                m_EnglishConverter = null;
                return;
            }
            if (cvt is MathConverter)
            {
                m_MathConverter = null;
                return;
            }
            if (cvt is PhoneticConverter)               // 音標轉換器.
            {
                m_PhoneticConverter = null;
                return;
            }

            m_Converters.Remove(cvt);
        }
        public void Test_TitleCase()
        {
            Assert.AreEqual(
                "Snow White and the Seven Dwarfs",
                WordConverter.ToTitleCase(
                    "snow white and the seven dwarfs",
                    TitleCaseExclusions.EnglishAndJapanese
                    )
                );

            Assert.AreEqual(
                "Brighton on Sea",
                WordConverter.ToTitleCase(
                    "brighton on sea",
                    TitleCaseExclusions.EnglishAndJapanese
                    )
                );

            Assert.AreEqual(
                "The Last of the Mohicans",
                WordConverter.ToTitleCase(
                    "the last of the mohicans",
                    TitleCaseExclusions.EnglishAndJapanese
                    )
                );

            Assert.AreEqual(
                "Ryū ga Gotoku",
                WordConverter.ToTitleCase(
                    "RYŪ GA GOTOKU",
                    TitleCaseExclusions.EnglishAndJapanese
                    )
                );

            Assert.AreEqual(
                "Bungaku Shōjo ni Tagari no Douke",
                WordConverter.ToTitleCase(
                    "bungaku shōjo ni tagari no douke",
                    TitleCaseExclusions.EnglishAndJapanese
                    )
                );

            // Todo: Include ignore option.
            // The current test is failing due to the 'O' being capitalized as per English rules.
            // A solution could include invoking different rules based on the exclusions
            // passed to the function. If the English optio is passed, the function follows English
            // rules. If the Japanese option is passed, it follows Japanese rules.

            Assert.AreEqual(
                "Kono Subarashii Sekai ni Shukufuku o!",
                WordConverter.ToTitleCase(
                    WordConverter.ToTitleCase(
                        "kono subarashii sekai Ni Shukufuku O!",
                        TitleCaseExclusions.English
                        ),
                    TitleCaseExclusions.Japanese
                    )
                );
        }
Exemple #5
0
        public void TestDocToDocxFile()
        {
            var docpath  = @"TestFiles\TestWordConverter\SPC_91079.DOC";
            var docxpath = WordConverter.ConvertDocToDocx(docpath);

            Assert.IsTrue(File.Exists(docxpath));
            File.Delete(docxpath);
        }
Exemple #6
0
        private void btnWordClick(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();

            op.ShowDialog();
            String    inputFile  = op.FileName;
            String    outputFile = String.Concat(inputFile, ".pdf");
            Converter converter  = new WordConverter();

            tryConvert(converter, inputFile, outputFile);
        }
Exemple #7
0
 public ApplicationCore(ReaderFinder readerFinder,
                        IImageBuilder tagCloudImageBuilder, ILayoutAlgorithm layoutAlgorithm,
                        IImageSaver imageSaver,
                        Filter filter, WordConverter wordConverter)
 {
     this.filter               = filter;
     this.wordConverter        = wordConverter;
     this.readerFinder         = readerFinder;
     this.tagCloudImageBuilder = tagCloudImageBuilder;
     this.imageSaver           = imageSaver;
     this.layoutAlgorithm      = layoutAlgorithm;
 }
Exemple #8
0
 public ConsoleUi(IReader[] readers,
                  IImageBuilder tagCloudImageCreator, ILayoutAlgorithm layoutAlgorithm,
                  IImageSaver imageSaver,
                  Filter filter, WordConverter wordConverter)
 {
     this.filter               = filter;
     this.wordConverter        = wordConverter;
     this.readers              = readers;
     this.tagCloudImageCreator = tagCloudImageCreator;
     this.imageSaver           = imageSaver;
     this.layoutAlgorithm      = layoutAlgorithm;
 }
Exemple #9
0
        public Task <string> ToHtml(IDocumentationProject documentationProject, string baseUri = "")
        {
            existingHeaderIds.Clear();

            WordPipeline wordPipeline = new WordPipelineBuilder()
                                        .UseAutoHeaderId(GenerateHeaderId, (generatedId) => { existingHeaderIds.Add(generatedId); })
                                        .UseLinkRewrite((originalUrl) => RewriteUrl(originalUrl, baseUri, documentationProject))
                                        .UseBootstrap()
                                        .UseBase64Image()
                                        .Build();

            return(WordConverter.ConvertToHtml(Document, wordPipeline));
        }
        public string Execute()
        {
            using (var dlg = new OpenFileDialog()
            {
                Filter = "Plik publikacji elektronicznej (*.epub)|*.epub"
            }) {
                if (dlg.ShowDialog() == DialogResult.OK)
                {
                    var docxFilePath = string.Empty;
                    var task         = new Task <string>(() => {
                        var result = new WordConverter().Execute(dlg.FileName, false);
                        return(result);
                    });

                    DevExpress.LookAndFeel.UserLookAndFeel.Default.SetSkinStyle(DevExpress.LookAndFeel.SkinStyle.Office2019Black);
                    SplashScreenManager.ShowDefaultWaitForm("Importowanie EPUB", "Proszę czekać...");

                    task.Start();
                    while (true)
                    {
                        if (task.Status != TaskStatus.Running && task.Status != TaskStatus.WaitingToRun)
                        {
                            break;
                        }
                        System.Threading.Thread.Sleep(500);
                    }

                    task.ContinueWith(t => {
                        if (t.Exception == null)
                        {
                            docxFilePath = t.Result;
                            Globals.ThisAddIn.Application.Documents.Open(docxFilePath);
                            SplashScreenManager.Default.CloseWaitForm();
                        }
                    });


                    //if (File.Exists(docxFilePath)) {
                    //    if (XtraMessageBox.Show("Czy nadpisać istniejący plik programu Word?", "Microsoft Word", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) {
                    //        return default;
                    //    }
                    //}

                    //document.Save(docxFilePath);



                    return(docxFilePath);
                }
            }
            return(default);
        public void TestTargetSpeciesExtractionLocal()
        {
            var pid = VMDPIDFactory.GetVmdPid().Result;

            foreach (var ep in pid.ExpiredProducts.Where(ep => !EPARTools.IsEPAR(ep.SPC_Link)))
            {
                var spc = VMDPIDFactory.GetSpc(ep).Result;
                Debug.WriteLine(spc);
                spc = spc.ToLowerInvariant().EndsWith(".doc") ? WordConverter.ConvertDocToDocx(spc) : spc;
                var ts = SPCParser.GetTargetSpecies(spc);
                Assert.IsNotNull(ts, $"null ts for {ep.Name}, {spc}");
                Assert.IsTrue(ts.Any(), $"empty ts for {ep.Name}, {spc}");
                Assert.IsFalse(ts.Any(string.IsNullOrWhiteSpace), $"blank species for {ep.Name}, {spc}");
            }
        }
Exemple #12
0
        public IEnumerable <WordViewModel> GetMatchesFromDb(string partial)
        {
            if (string.IsNullOrEmpty(partial))
            {
                return(null);
            }
            var entities = _repository.GetMatches(partial);
            var output   = new List <WordViewModel>();

            foreach (var entity in entities)
            {
                output.Add(WordConverter.ConvertFromEntity(entity));
            }
            return(output);
        }
        public void TestTargetSpeciesExtractionFromDocOldFormat()
        {
            const string pathtospc = @"TestFiles\TestSPCParser\SPC_124816.doc";

            var expectedoutput = new[]
            {
                "cats"
            };
            var pathtodocx        = WordConverter.ConvertDocToDocx(pathtospc);
            var ts                = SPCParser.GetTargetSpecies(pathtodocx);
            var intersectioncount = ts.Intersect(expectedoutput).Count();

            Assert.IsTrue(intersectioncount == expectedoutput.Length,
                          $"Intersection count:{intersectioncount}, expected {expectedoutput.Length}");
        }
Exemple #14
0
        private void ConvertPanelFuncDrop(DragEventArgs e)
        {
            Dispatcher.Invoke(() => ConvertProgressBar.Visibility = Visibility.Visible);

            List <string> paths = new List <string>();

            foreach (string obj in (string[])e.Data.GetData(DataFormats.FileDrop))
            {
                if (Directory.Exists(obj))
                {
                    paths.AddRange(Directory.GetFiles(obj, "*.*", SearchOption.AllDirectories));
                }
                else
                {
                    paths.Add(obj);
                }
            }

            int count = paths.Count;

            Dispatcher.Invoke(() => ConvertProgressBar.Maximum = count);

            for (int i = 0; i < count; i++)
            {
                String inputFile = paths[i];
                int    lngth     = inputFile.Length;

                if (inputFile[lngth - 1] == 'c' || inputFile[lngth - 2] == 'c')
                {
                    String    outputFile = String.Concat(inputFile, ".pdf");
                    Converter converter  = new WordConverter();
                    tryConvert(converter, inputFile, outputFile.Replace(".docx", ""));
                }

                Dispatcher.Invoke(() => ConvertProgressBar.Value++);
            }

            if (count > 0)
            {
                MessageBox.Show("Конвертация завершена", "Готово");
            }

            Dispatcher.Invoke(() => ConvertProgressBar.Visibility = Visibility.Hidden);
            Dispatcher.Invoke(() => ConvertLabelText.Content      = "Drop or click for convert file(s)");
        }
Exemple #15
0
        public async Task <IEnumerable <WordViewModel> > GetMatchesFromWebService(string partial, string locale)
        {
            if (string.IsNullOrEmpty(partial))
            {
                return(null);
            }

            var entities = await _service.GetAsync(partial, locale);

            var output = new List <WordViewModel>();

            foreach (var entity in entities)
            {
                output.Add(WordConverter.ConvertFromWebService(entity as Word));
            }

            return(output);
        }
Exemple #16
0
        private void btnWordClick(object sender, EventArgs e)
        {
            OpenFileDialog op = new OpenFileDialog();

            op.ShowDialog();
            String src         = op.FileName;
            var    contentType = MimeTypes.GetContentType(src);

            if (contentType != "application/msword")
            {
                string msg = "源文件应为word文件";
                MessageBox.Show(msg);
                return;
            }
            String    outputFile = String.Concat(src, ".pdf");
            Converter converter  = new WordConverter();

            tryConvert(converter, src, outputFile);
        }
Exemple #17
0
        static void Main(string[] args)
        {
            string path = @"D:\VisualStudioProjects\UntitledOfficeConverter\TestFiles\sven.docx";

            using (var wrd = new WordConverter())
            {
                wrd.Convert(path);
            }
            path = @"D:\VisualStudioProjects\UntitledOfficeConverter\TestFiles\a.pptx";
            using (var wrd = new PowerPointConverter())
            {
                wrd.Convert(path);
            }

            path = @"D:\VisualStudioProjects\UntitledOfficeConverter\TestFiles\hist.xlsx";
            using (var wrd = new ExcelConverter())
            {
                wrd.Convert(path);
            }
        }
Exemple #18
0
        static int Main(string[] args)
        {
            if (args.Length != 2)
            {
                System.Console.WriteLine("Usage: .exe wordFilePathName(*.doc,*.docx) saveAsPathName(*.pdf)");
                return(1);
            }
            string wordFilePathName = System.IO.Path.GetFullPath(args[0]);
            string saveAsPathName   = System.IO.Path.GetFullPath(args[1]);

            try
            {
                WordConverter.SaveAsPdf(wordFilePathName, saveAsPathName);
            }
            catch (System.Exception e)
            {
                System.Console.WriteLine(e);
                return(1);
            }
            return(0);
        }
Exemple #19
0
        public string Execute(string fileName, bool loadLicenseKey = true)
        {
            var converter = new WordConverter();
            var doc       = converter.GetDocument(fileName, loadLicenseKey);

            if (doc != null)
            {
                var pdfFilePath = Path.Combine(Path.GetDirectoryName(fileName), Path.GetFileNameWithoutExtension(fileName) + ".pdf");
                doc.Save(pdfFilePath, new Aspose.Words.Saving.PdfSaveOptions()
                {
                    UseHighQualityRendering = true,
                    ExportDocumentStructure = true,
                    EmbedFullFonts          = true,
                    Compliance           = Aspose.Words.Saving.PdfCompliance.PdfA2a,
                    JpegQuality          = 100,
                    CreateNoteHyperlinks = true
                });
                return(pdfFilePath);
            }

            return(null);
        }
Exemple #20
0
        private void ConvertPanelFuncClick(MouseButtonEventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();

            ofd.Filter = "Файлы docx|*.docx|Файлы doc|*.doc";
            ofd.ShowDialog();

            int count = ofd.FileNames.Length;

            if (count > 0)
            {
                Dispatcher.Invoke(() => ConvertProgressBar.Visibility = Visibility.Visible);
                Dispatcher.Invoke(() => ConvertLabelPanel.Visibility  = Visibility.Hidden);
                Dispatcher.Invoke(() => imgConvert.Visibility         = Visibility.Visible);
            }
            Dispatcher.Invoke(() => ConvertProgressBar.Maximum = count);
            for (int i = 0; i < count; i++)
            {
                String inputFile = ofd.FileNames[i];
                int    lngth     = inputFile.Length;
                if (inputFile[lngth - 1] == 'c' || inputFile[lngth - 2] == 'c')
                {
                    String    outputFile = String.Concat(inputFile, ".pdf");
                    Converter converter  = new WordConverter();
                    tryConvert(converter, inputFile, outputFile);
                }
                Dispatcher.Invoke(() => ConvertProgressBar.Value++);
            }
            if (count > 0)
            {
                MessageBox.Show("Конвертация завершена", "Готово");
            }

            Dispatcher.Invoke(() => ConvertProgressBar.Visibility = Visibility.Hidden);
            Dispatcher.Invoke(() => ConvertLabelPanel.Visibility  = Visibility.Visible);
            Dispatcher.Invoke(() => imgConvert.Visibility         = Visibility.Hidden);
            Dispatcher.Invoke(() => ConvertLabelText.Content      = "Drop or click for convert file(s)");
        }
        public void AddConverter(WordConverter cvt)
        {
            // 設定已知的轉換器。

            if (cvt is ContextTagConverter)
            {
                m_ContextTagConverter = (ContextTagConverter)cvt;
                return;
            }
            if (cvt is ChineseWordConverter)
            {
                m_ChineseConverter = (ChineseWordConverter)cvt;
                return;
            }
            if (cvt is EnglishWordConverter)
            {
                m_EnglishConverter = (EnglishWordConverter)cvt;
                return;
            }
            if (cvt is MathConverter)   // 數學符號轉換器.
            {
                m_MathConverter = (MathConverter)cvt;
                return;
            }
            if (cvt is PhoneticConverter)               // 音標轉換器.
            {
                m_PhoneticConverter = (PhoneticConverter)cvt;
                return;
            }

            // 加入其他未知的轉換器。
            if (m_Converters.IndexOf(cvt) < 0)
            {
                m_Converters.Add(cvt);
            }
        }
Exemple #22
0
 public TagsCloudCreator(ITagsCloudLayouter layouter, IWordHandler wordHandler, WordConverter wordConverter)
 {
     Layouter      = layouter;
     WordHandler   = wordHandler;
     WordConverter = wordConverter;
 }