public void Convert_When_WordFileNotFound_Then_NullIsRetuned()
        {
            WordToPdfConverter converter   = new WordToPdfConverter();
            string             newFilePath = converter.Convert("test.docx", "Temp");

            Assert.That(newFilePath, Is.Null);
        }
        public static IConverter GetConverter(SupportedExtensions extension)
        {
            IConverter converter = null;

            switch (extension)
            {
            case SupportedExtensions.doc:
            case SupportedExtensions.docx:
                converter = new WordToPdfConverter();
                break;

            case SupportedExtensions.ppt:
            case SupportedExtensions.pptx:
                converter = new PowerPointToPdfConverter();
                break;

            case SupportedExtensions.xls:
            case SupportedExtensions.xlsx:
                converter = new ExcelToHtmlConverter();
                break;

            case SupportedExtensions.rtf:
                converter = new RtfToPdfConverter();
                break;

            case SupportedExtensions.eml:
            case SupportedExtensions.msg:
                converter = new MailToHtmlConverter();
                break;
            }
            return(converter);
        }
Example #3
0
 public HomeController(WordToPdfConverter wordToPdfConverter,
                       PdfToPngConverter pdfToPngConverter,
                       ReportRenderer reportRenderer)
 {
     this.wordToPdfConverter = wordToPdfConverter;
     this.pdfToPngConverter  = pdfToPngConverter;
     this.reportRenderer     = reportRenderer;
 }
        public void Convert_When_WordFileIsFound_Then_NewFilePathIsReturned()
        {
            WordToPdfConverter converter   = new WordToPdfConverter();
            string             root        = Path.GetDirectoryName(Path.GetDirectoryName(TestContext.CurrentContext.TestDirectory));
            string             newFilePath = converter.Convert(Path.Combine(root, "Samples\\sample.docx"), Path.Combine(root, "Temp"));

            Assert.That(newFilePath, Is.Not.Null);
            Assert.That(Path.GetExtension(newFilePath), Is.EqualTo(".pdf"));
        }
Example #5
0
        public void should_convert_from_word_to_pdf()
        {
            string from = Environment.CurrentDirectory + @"\TestFiles\智慧市政综合指挥平台.docx";
            string to   = Environment.CurrentDirectory + @"\TestFiles\智慧市政综合指挥平台docx.pdf";

            WordToPdfConverter converter = new WordToPdfConverter();

            Assert.AreEqual(ErrorMessages.Success, converter.Convert(from, to));
            Assert.IsTrue(File.Exists(to));
        }
        public void Convert_When_WordDestinationPathDoesNotExist_Then_DirectoryIsCreated()
        {
            string             currentDateSpan = DateTime.Now.Ticks.ToString();
            WordToPdfConverter converter       = new WordToPdfConverter();
            string             root            = Path.GetDirectoryName(Path.GetDirectoryName(TestContext.CurrentContext.TestDirectory));

            Assert.That(Directory.Exists(Path.Combine(root, "Temp" + currentDateSpan)), Is.False);
            converter.Convert(Path.Combine(root, "Samples\\sample.docx"), Path.Combine(root, "Temp" + currentDateSpan));
            Assert.That(Directory.Exists(Path.Combine(root, "Temp" + currentDateSpan)), Is.True);
            Directory.Delete(Path.Combine(root, "Temp" + currentDateSpan), true);
        }
Example #7
0
 public HomeController(WordToPdfConverter wordToPdfConverter,
                       PdfToPngConverter pdfToPngConverter,
                       ReportRenderer reportRenderer,
                       DirectoryWatcher directoryWatcher,
                       IHostingEnvironment hostingEnvironment,
                       IMemoryCache memoryCache)
 {
     this.wordToPdfConverter = wordToPdfConverter;
     this.pdfToPngConverter  = pdfToPngConverter;
     this.reportRenderer     = reportRenderer;
     this.directoryWatcher   = directoryWatcher;
     this.hostingEnvironment = hostingEnvironment;
     this.memoryCache        = memoryCache;
 }
Example #8
0
        public static string ConvertDocToPDF(string b_file)
        {
            try
            {
                string partShare       = WebConfigurationManager.AppSettings["ServerLinkFile"];
                string LinkServerLocal = WebConfigurationManager.AppSettings["ServerLocal"];
                //b_file = HttpContext.Current.Server.MapPath("~") + b_file;
                if (!File.Exists(b_file))
                {
                    return(string.Empty);
                }
                string ex = System.IO.Path.GetExtension(b_file);

                DateTime lastModified = System.IO.File.GetLastWriteTime(b_file);

                var lastModifiedString = lastModified != null?lastModified.ToString("yyyyMMddHHmmss") : "0";

                string b_out = b_file.Replace("/Files/", "/Files/tmp/").Replace(ex, string.Format("_{0}.pdf", lastModifiedString));

                var temp = Path.GetDirectoryName(b_out);
                if (!Directory.Exists(temp))
                {
                    Directory.CreateDirectory(temp);
                }

                if (File.Exists(b_out))
                {
                    if (!string.IsNullOrEmpty(LinkServerLocal))
                    {
                        b_out = b_out.Replace(LinkServerLocal, string.Empty);
                    }
                    else
                    {
                        b_out = b_out.Replace("////" + partShare, string.Empty);
                    }

                    return(b_out);
                }

                // Create a Word to PDF converter object with default settings
                WordToPdfConverter wordToPdfConverter = new WordToPdfConverter();

                // Set license key received after purchase to use the converter in licensed mode
                // Leave it not set to use the converter in demo mode
                wordToPdfConverter.LicenseKey = "gA4eDxofD2YCeE5dSlVwHR8eGA8YARsPHB4BHh0BFhYWFg8e";

                // Convert the Word document to a PDF document
                byte[] outPdfBuffer = wordToPdfConverter.ConvertWordFile(b_file);

                // Write the memory buffer in a PDF file
                System.IO.File.WriteAllBytes(b_out, outPdfBuffer);

                if (!string.IsNullOrEmpty(LinkServerLocal))
                {
                    b_out = b_out.Replace(LinkServerLocal, string.Empty);
                }
                else
                {
                    b_out = b_out.Replace("////" + partShare, string.Empty);
                }
                return(b_out);
            }
            catch (Exception ex)
            {
                LogController.WriteLog(LogApp.BatchfileApp, "Helper.ConvertDocToPDF", LogType.Exception, "", ex.ToString(), log_dir);
                return(string.Empty);
            }
        }