public void ConvertFromXmlToJsonFormat_ResultOutputInJsonFormat()
        {
            var model = MockAssets.SeedDocumentTestDocument();
            var xml   = MockAssets.SeedXmlDocument(model);

            var expected = MockAssets.SeedJsonDocument(model);

            var actual = _sut.Convert(Format.Xml, Format.Json, xml);

            var actualTextNormalized   = Regex.Replace(actual, @"\s+", string.Empty);
            var expectedTextNormalized = Regex.Replace(expected, @"\s+", string.Empty);

            actualTextNormalized.Should().BeEquivalentTo(expectedTextNormalized);
        }
        static void Main(string[] args)
        {
            var storagePath = Path.Combine(RootFolder, "TestFiles");

            // Set license
            License license = new License();

            license.SetLicense("");

            // Setup Conversion configuration
            var conversionConfig = new ConversionConfig
            {
                StoragePath = storagePath,
                OutputPath  = ResultPath,
                UseCache    = false
            };

            var inputDataHandler  = new GoogleInputHandler(conversionConfig);
            var conversionHandler = new ConversionHandler(conversionConfig, inputDataHandler);

            var resultStream = conversionHandler.Convert <Stream>("document.gdoc", new WordsSaveOptions());

            WriteStreamToFile(resultStream, "result.docx");
            resultStream.Dispose();

            Console.WriteLine("The conversion finished. Press <<ENTER>> to exit.");
            Console.ReadLine();
        }
Exemple #3
0
        // Advanced example
        public static void ToCellsAdvance()
        {
            // Setup Conversion configuration
            var conversionConfig = new ConversionConfig {
                StoragePath = storagePath, CachePath = cachePath
            };

            conversionConfig.SetUseCache(true);

            //instantiating the conversion handler
            var conversionHandler = new ConversionHandler(conversionConfig);

            //Set password to unprotect protected document during loading
            LoadOptions loadOptions = new LoadOptions {
                Password = "******"
            };

            // convert file to Xls, starting from page 2 and convert 2 pages
            SaveOptions saveOptions = new CellsSaveOptions
            {
                ConvertFileType   = CellsSaveOptions.CellsFileType.Xls,
                PageNumber        = 2,
                NumPagesToConvert = 2
            };

            var convertedDocumentStream = conversionHandler.Convert <Stream>(inputGUIDFile, loadOptions, saveOptions);
        }
Exemple #4
0
        static void Main()
        {
            const string sourceFileName = "sample.doc"; //TODO: Put the source filename here
            const string resultFileName = "result.pdf"; //TODO: Put the result filename here

            // Setup Conversion configuration
            var conversionConfig = new ConversionConfig
            {
                CachePath   = "cache",
                StoragePath = "."
            };

            conversionConfig.SetUseCache(true);

            var inputDataHandler  = new AmazonInputDataHandler();
            var cacheDataHandler  = new AmazonCacheDataHandler(conversionConfig);
            var conversionHandler = new ConversionHandler(conversionConfig, inputDataHandler, cacheDataHandler);

            var resultStream = conversionHandler.Convert <Stream>(sourceFileName, new PdfSaveOptions());

            WriteStreamToFile(resultStream, resultFileName);
            resultStream.Dispose();

            Console.WriteLine("The conversion finished. Press <<ENTER>> to exit.");
            Console.ReadLine();
        }
Exemple #5
0
        // Advanced example
        public static void ToSlidesAdvance()
        {
            // Setup Conversion configuration
            var conversionConfig = new ConversionConfig {
                StoragePath = storagePath, CachePath = cachePath
            };

            conversionConfig.SetUseCache(true);

            //instantiating the conversion handler
            var conversionHandler = new ConversionHandler(conversionConfig);

            //Set password to unprotect protected document during loading
            LoadOptions loadOptions = new LoadOptions {
                Password = "******"
            };

            // convert file to Ppt, starting from page 2 and convert 2 pages,
            // use DPI 300, image width 1024, image height 768
            SaveOptions saveOptions = new SlidesSaveOptions
            {
                ConvertFileType   = SlidesSaveOptions.SlidesFileType.Ppt,
                PageNumber        = 2,
                NumPagesToConvert = 2,
            };

            var convertedDocumentStream = conversionHandler.Convert <Stream>(inputGUIDFile, loadOptions, saveOptions);
        }
Exemple #6
0
        public static void Main(string[] args)
        {
            Console.WriteLine(AmlRiderLogo.Replace("@", Environment.NewLine));
            Console.WriteLine("For help use the --help flag!" + Environment.NewLine);

            new CommandLineParser()
            .Parse(args, typeof(ConvertOptions), typeof(PackageOptions))
            .WithParsed <ConvertOptions>(OnConvertOptionsParsed)
            .WithParsed <PackageOptions>(OnPackageOptionsParsed);

            if (HasParsedArgs || args.Length < 1)
            {
                return;
            }

            var path = args[0];

            if (!File.Exists(path))
            {
                Console.WriteLine($"The file {path} does not exist.");
                return;
            }

            var outputFile = ConstructOutputFilePath(path);

            if (!ShouldOverride(outputFile))
            {
                return;
            }

            var fileText  = ReadFile(path);
            var outputXml = ConversionHandler.Convert(fileText, outputFile);

            File.WriteAllText(outputFile, outputXml);
        }
Exemple #7
0
        // Result as Stream
        public static void ToCellsAsStream()
        {
            // Setup Conversion configuration
            var conversionConfig = new ConversionConfig {
                StoragePath = storagePath, CachePath = cachePath
            };

            //instantiating the conversion handler
            var conversionHandler = new ConversionHandler(conversionConfig);

            var convertedDocumentStream = conversionHandler.Convert <Stream>(inputGUIDFile, new CellsSaveOptions());
        }
Exemple #8
0
        //public static string inputGUIDFile = "Slidessample.Pdf";

        // Result as file path
        public static void ToSlidesAsPath()
        {
            // Setup Conversion configuration
            var conversionConfig = new ConversionConfig {
                StoragePath = storagePath, CachePath = cachePath
            };

            //instantiating the conversion handler
            var conversionHandler = new ConversionHandler(conversionConfig);

            var convertedDocumentPath = conversionHandler.Convert <string>(inputGUIDFile, new SlidesSaveOptions());
        }
        private static void ConvertPdfToHtml()
        {
            Console.WriteLine("Press any key to convert PDF to HTML ... ");
            Console.ReadKey();

            // Convert document
            var result = _conversionHandler.Convert <Stream>("sample.pdf", new HtmlSaveOptions());

            // Write converted stream to file
            WriteStreamToFile(result, "result.html");
        }
        //public static string inputGUIDFile = "PDFsample.pdf";

        // Result as file path
        public static void ToImageAsPath()
        {
            // Setup Conversion configuration
            var conversionConfig = new ConversionConfig {
                StoragePath = storagePath, CachePath = cachePath
            };

            //instantiating the conversion handler
            var conversionHandler = new ConversionHandler(conversionConfig);

            var convertedDocumentPath = conversionHandler.Convert <IList <string> >(inputGUIDFile, new ImageSaveOptions {
                ConvertFileType = ImageSaveOptions.ImageFileType.Jpg
            });
        }
        protected void lnkbtn_Convert_OnClick(object sender, EventArgs e)
        {
            /*
             * CONVERT ALL THE FILES TO PDF FORMAT & STORE IN OUTPUT_DIRECTORY
             */
            foreach (ListItem files in lst_SourceFiles.Items)
            {
                //SET UPLOAD FOLDER
                filePath = Server.MapPath("~/Uploads/");

                //SET CACHE FOLDER WHERE THE CONVERSION TEMPORARY FILES ARE RUNNING
                cachePath = Server.MapPath("~/Cache/");

                //SET OUTPUT FOLDER WHERE THE ACTUAL FILES WILL BE PLACED AFTER CONVERSION
                outputPath = Server.MapPath("~/OutputDir/");

                //ORIGINAL FILE NAME WITH EXTENSION e.g SAMPLEFILE1.DOC
                string file = files.Text;

                //CONVERSION CONFIGURATION FOR DEFAULT
                ConversionConfig _conConfg = new ConversionConfig
                {
                    StoragePath = filePath,
                    CachePath   = cachePath,
                    OutputPath  = outputPath
                };

                ConversionHandler conversionHandler = new ConversionHandler(_conConfg);

                //CONVERSION TO PDF VIA FILE PATH
                var convertedPDF = conversionHandler.Convert <string>(file, new PdfSaveOptions
                {
                    ConvertFileType = PdfSaveOptions.PdfFileType.Pdf,
                    OutputType      = OutputType.String
                });
            }

            //GETS ALL THE CONVERTED FILES FROM OUTPUT FOLDER
            string[] myOutputFiles = Directory.GetFiles(outputPath);
            foreach (var items in myOutputFiles)
            {
                lst_DestinationFiles.Items.Add(new ListItem(Path.GetFileName(items), items));
            }

            lbl_destinationFiles.Text = @"All " + myOutputFiles.Length + " have been successfully synced!";
        }
Exemple #12
0
        private static void OnConvertOptionsParsed(ConvertOptions options)
        {
            HasParsedArgs = true;
            if (!File.Exists(options.File))
            {
                Console.WriteLine($"The file {options.File} does not exist.");
                return;
            }

            var    fileText = ReadFile(options.File);
            string amlRoot;

            var outputFile = options.Output;

            if (string.IsNullOrWhiteSpace(outputFile))
            {
                outputFile = ConstructOutputFilePath(options.File);
            }

            try
            {
                amlRoot = ConversionHandler.Convert(fileText, outputFile);
            }
            catch (Exception)
            {
                Console.WriteLine("An error occurred during conversion. The file has probably an invalid format.");
                return;
            }

            try
            {
                if (!ShouldOverride(outputFile))
                {
                    return;
                }

                File.WriteAllText(outputFile, amlRoot);
            }
            catch (IOException)
            {
                Console.WriteLine(
                    "Unable to write output file. Maybe you are missing permissions or the file is opened in another software");
                return;
            }
        }
        private static void ConvertPdfToImage(string fileName, ImageSaveOptions.ImageFileType outputFileType)
        {
            String sourcePath = @"C:\";
            String targetPath = @"D:\";

            var conversionConfig = new ConversionConfig {
                StoragePath = sourcePath, OutputPath = targetPath
            };

            var conversionHandler = new ConversionHandler(conversionConfig);

            var saveOptions = new ImageSaveOptions
            {
                ConvertFileType = outputFileType
            };

            var convertedDocumentPath = conversionHandler.Convert(sourcePath + fileName, saveOptions);

            for (int pageNum = 1; pageNum < convertedDocumentPath.PageCount; pageNum++)
            {
                convertedDocumentPath.Save("Output-" + Path.GetFileNameWithoutExtension(fileName) + pageNum.ToString() + "." + outputFileType, pageNum);
            }
        }
        static void Main()
        {
            const string sourceFileName = "sample.doc"; //TODO: Put the source filename here

            // Setup Conversion configuration
            var conversionConfig = new ConversionConfig
            {
                OutputPath  = "result",
                StoragePath = "."
            };

            conversionConfig.UseCache = true;

            var inputDataHandler  = new AmazonInputDataHandler();
            var outputDataHandler = new AmazonOutputDataHandler(conversionConfig);
            var conversionHandler = new ConversionHandler(conversionConfig, inputDataHandler, outputDataHandler);

            var resultPath = conversionHandler.Convert <string>(sourceFileName, new PdfSaveOptions {
                OutputType = OutputType.String
            });

            Console.WriteLine("The conversion finished. The result can be located here: {0}. Press <<ENTER>> to exit.", resultPath);
            Console.ReadLine();
        }
Exemple #15
0
        protected void btnConvertAll_Click(object sender, EventArgs e)
        {
            // string lblFilesConverted = string.Empty;
            if (lstSourceFiles.Items.Count > 0)
            {
                lblConvStatus.Text    = "Conversion started. Please wait....";
                lblConvStatus.Visible = true;
                string outputfilename = string.Empty;
                foreach (ListItem lstItem in lstSourceFiles.Items)
                {
                    inputFile      = lstItem.Text;
                    outputfilename = Path.GetFileNameWithoutExtension(inputFile) + ".pdf";
                    ListItem item = lstTargetFiles.Items.FindByValue(outputfilename);
                    if (item == null)
                    {
                        try
                        {
                            //one way
                            conversionConfig = new ConversionConfig {
                                OutputPath = outputPath, StoragePath = storagePath, CachePath = cachePath
                            };
                            conversionHandler     = new ConversionHandler(conversionConfig);
                            convertedDocumentPath =
                                conversionHandler.Convert <string>(inputFile, new PdfSaveOptions {
                                OutputType = OutputType.String
                            });

                            /* // another way
                             * conversionConfig = new ConversionConfig()
                             * {
                             *  OutputPath = outputPath,
                             *  CachePath = cachePath,
                             *  LocalesPath = cachePath,
                             *  StoragePath = storagePath,
                             *  UseCache = false
                             * };
                             *
                             *
                             * ConversionHandler conversionHandler = new ConversionHandler(conversionConfig);
                             * //check whether file suppoted
                             * var availableConversions = conversionHandler.GetSaveOptions(Path.GetExtension(inputFile).Replace(".", ""));
                             * PdfSaveOptions saveOptions = new PdfSaveOptions()
                             * {
                             *  ConvertFileType = PdfSaveOptions.PdfFileType.Pdf,
                             *  PageNumber = 1,
                             *  NumPagesToConvert = 1,
                             *  CustomName = Path.GetFileNameWithoutExtension(inputFile),
                             *  OutputType = OutputType.String
                             * };
                             * var memStream = new MemoryStream(File.ReadAllBytes(storagePath + "" + inputFile));
                             * convertedDocumentPath = conversionHandler.Convert<String>(memStream, saveOptions);
                             */
                            lstTargetFiles.Items.Add(outputfilename);
                        }
                        catch (Exception ex)
                        {
                            lblWrongFormat.Text    = inputFile + " issue - " + ex.Message;
                            lblWrongFormat.Visible = true;
                        }
                    }
                    else
                    {
                        lblConvStatus.Text = inputFile + " file already converted.";
                    }
                }
                lblConvStatus.Text = "Conversion completed.";
            }
        }